RE: Date weirdness (php/mysql) (code included)
| From: | Michael Hall | Date: | Wed, 08 Nov 2000 21:24:36 +0000 |
| Subject: | RE: Date weirdness (php/mysql) (code included) | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-4318@lists.php.net to get a copy of this message | ||
I'm a digest guy, so I'm sorry if this has already been beaten to death.
The date() function expects a UNIX timestamp, which you could get using the
mktime() function.
the format is:
mktime (hour, minute, second, month, day, year)
Here's how I'd do it.
Select day, month, and year separately from the database by changing the sql
statement like so:
select news.*, year(thedate) as year, month(thedate) as month,
dayofmonth(thedate) as day from news.....
Then create a variable to hold your timestamp. The first three numbers I
made up, because you aren't concerned with the time of day:
$epoch = mktime(12,12,12,$row[month],$row[day],$row[year]);
from then on, instead of $row[thedate] you would use $epoch in the date()
function ( e.g. date("F d, Y", $epoch) ).
Hope I didn't confuse.
Michael Hall
Database Engineer
Prairie Fire Web Design
mike@prairiefirewebdesign.com
> -----Original Message-----
> From: John Guynn [mailto:John.Guynn@telescan.com]
> Sent: Wednesday, November 08, 2000 2:27 PM
> To: Php-Db (E-mail)
> Subject: Date weirdness (php/mysql) (code included)
>
>
> I am storing dates in a MySQL database in the YYYY-MM-DD format.
>
> $thisyear = "2000"; (sets current year)
> echo $thisyear."<br>"; (debugging code)
> $result = mysql_query("SELECT * FROM news WHERE YEAR(thedate) =
> '$thisyear'
> ORDER BY thedate"); (select statement)
> while ($row = mysql_fetch_array ($result)) {
> echo "<br>".$row[thedate]."<br>"; (debugging again)
> printf ("<h5 class=\"h5headl\">%s </h5>",date("F d,
> Y",$row[thedate]));
> (prints EVERY date as December 31, 1969)
> echo "<p class=\"story\">";
> printf ("%s <a href=\"mar2000.php3\">%s's
> Results</a>",$row[info],date("F",$row[thedate])); (prints EVERY month as
> December)
> echo "<br>";
> }
>
> What am I doing wrong? Is php's date() expecting a different format than
> YYYY-MM-DD? The date range from 2000-03-26 to 2000-07-30. Nothing near
> 1969-12-31.
>
> Ideas or suggestions appreciated.
>
> John Guynn
>