Forum Moderators: coopster
I used 'timestamp' data-type of length '14' in MySQL applied now() automatically and accurately to all inputs.
echo date("l, F d, Y", '20050619021942'); returns Tuesday, January 19, 2038
echo date("l, F d, Y", strtotime('20050619021942')); returns nothing
gmdate() lieu date() also behaves same; I'm puzzled; what problem PHP has?
$var = date("l, F d Y");
$var = strtotime($var);
echo date("l, F d, Y", $var);
$var = mktime(date("l, F d, Y"));
echo date("l, F d, Y", $var);
Above returns date correctly. Why I use PHP to construct and store time when MySQL do itself correctly?
If also compared outputs of mktime() of PHP and now() of MySQL; mktime() returns something unintelligible to me, now() output resembles in yyyymmddhhmmss format.
$var = "20050619021942";
$var = strtotime($var);
echo date("l, F d, Y", $var);
Above displays nothing. Why?
The format required by date() is that returned from the function time(), it is something like seconds since 01/01/1970. That's why the version you are attempting to use, or save, ie YYYYMMDDHHMMII, does not work with it.
You're just using the wrong format. If you review the php manual pages it gives you this advice, it also offers you details of timestamp conversion routines, and a link through to the applicable MySQL pages.
That date is the Y2K38 rollover date, the date when it rolls back to zero again (can't remember if that resets the date back to 1900 or 1970 at the moment).
Are you preparing for that yet? or have you got your head in the sand like everyone had for the first rollover problem just over five years ago, when 1999 rolled over to 1900 instead of 2000?
SELECT UNIX_TIMESTAMP(fld_timestamp) as fld_unixTimestamp FROM tbl_example Also, remember that mysql has a date_format() function as well.
For example, I'm in Eastern Time zone (EST) which is -5.00 hours from GMT. Somewhere I'll save in MySQL that I'm in EST and my code would calculate -5 hours from GMT zone to display to me the correct time.
These two links will become your best friend here...
Burner
The base reference is UTC and you are well advised to use that instead. See also International Standard: ISO 8601, as well as RFC 3339, and related documents.
$timezone_offset=-5; //I'm in EST
$now = gmdate("M d Y H:i:s", mktime($hour+$timezone_offset, $minute, $second, $month, $day, $year));
Now if I need to calculate the time for a timezone say 1 month from today it becomes:
$timezone_offset=-5; //I'm in EST
$then = gmdate("M d Y H:i:s", mktime($hour+$timezone_offset, $minute, $second, $month+1, $day, $year));
But like I say, I'm a creature of habit so there may be a more efficient way to do it...
Burner
PS if you paste that code from above make sure you populate the vars $year, $month, $day etc...
Just for ideal: [timeanddate.com...]
[edited by: jatar_k at 3:41 pm (utc) on June 22, 2005]
[edit reason] lets not do that thank you [/edit]
UTC is derived from Atomic Clocks, and is kept in step with the Sun by the addition of leap seconds (refer to ISO 8601 for more).
A clock showing GMT will show the same time as one showing UTC, but UTC is the correct designation to use to describe that time.