making sense of time(), date() and strtotime()
| From: | Justin French | Date: | Thu, 29 May 2003 12:48:52 +0000 |
| Subject: | making sense of time(), date() and strtotime() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-149395@lists.php.net to get a copy of this message | ||
I have $_POST['day'] (1-31), $_POST['month'] (1-12), $_POST['year']
(2003-2004).
I store all dates as unix (epoch) timestamps, and generate the timestamp for
the event with:
strtotime('{$_POST['month']}/{$_POST['day']}/{$_POST['day']}');
Everything works fine on my LAN (Australia), but when I upload my database
to the live server (US), the dates are a day behind (when echo'd with
date('Y-m-d')), presumably due to the time difference between the two
servers.
Timestamps generated directly on the live server appear correct when echoed
out using date.
How can I reliably generate timestamps which will work on any server, and
reliably convert these timestamps to human readable format (eg
date('Y-m-d')) on any server?
Is the key to use GMT in the strtotime() string and use gmdate() instead of
date()? Or is it more complex than that?
Thanks,
Justin French