RE: [PHP] Newby: DATE Question
| From: | John W. Holmes | Date: | Thu, 24 Oct 2002 16:01:57 +0000 |
| Subject: | RE: [PHP] Newby: DATE Question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-121298@lists.php.net to get a copy of this message | ||
> In my MySQL database I have a column that is a TIMESTAMP to
automatically
> stamp the date when created. However, I can't get it to pull
correctly
> into
> my php result.
>
> Here is a sample of one record that has the value of 20021024083050 in
the
> date column.
>
> In my php code I have the following pieces of coding (there's more
than
> this, but this is what's returning the date).
> $query = "SELECT * FROM posting ORDER BY date DESC";
> $date = strftime("%d/%m/%y", $thread['date']);
>
> And this is the result I receive: Result: 18/01/38
MySQL and Unix(PHP) timestamps are different formats. Use DATE_FORMAT
(MySQL equivalent of PHP's date()) in your query, or store unix
timestamps that you can use in date() and strftime(). You could also use
the TO_UNIXTIME() function in mysql to convert your TIMESTAMP into a
Unix timestamp.
More details in the manual...
---John Holmes...