You can do this in this way,
<?php
try {
$date = new DateTime('2040-01-01 14:30:30');//Or only date e.g $date = new DateTime('2040-01-01');
} catch (Exception $e) {
echo $e->getMessage();
exit(1);
}
echo $date->format('Y-m-d H:i:s');//date format used in date function
?>
try {
$date = new DateTime('2040-01-01 14:30:30');//Or only date e.g $date = new DateTime('2040-01-01');
} catch (Exception $e) {
echo $e->getMessage();
exit(1);
}
echo $date->format('Y-m-d H:i:s');//date format used in date function
?>
See http://php.net/manual/en/book.datetime.php
ARIF MAHMUD RANA
From: ymnoor21 <ymnoor21@yahoo.com>
To: phpexperts@yahoogroups.com
Sent: Tuesday, June 28, 2011 6:26 AM
Subject: [phpXperts] Interesting Problem!!!
Hi everyone,
I was working with PHP's core date function and came across an interesting problem. Ex:
echo date("m/d/Y", strtotime("2038-01-18"));
prints: 01/18/2038
but if you go beyond that date, then it goes back to this: 12/31/1969
Looks like i've hit the wall. I knew that PHP had a setdate limitation for unix (1902 - 2037) & for windows (1971 - 2037). But my question was why it would show me a date of 2038 even though they are limited to year 2037 by theory? Probably something to do with 32bit or 64bit issue. Anyway, i have to deal a workaround for setting future dates (ex: 12/31/2111), unless if you guys have any solution using PHP's core date object / function.
Please do let me know if you find this problem interesting & have a good solution for this.
Thanks
Yamin
I was working with PHP's core date function and came across an interesting problem. Ex:
echo date("m/d/Y", strtotime("2038-01-18"));
prints: 01/18/2038
but if you go beyond that date, then it goes back to this: 12/31/1969
Looks like i've hit the wall. I knew that PHP had a setdate limitation for unix (1902 - 2037) & for windows (1971 - 2037). But my question was why it would show me a date of 2038 even though they are limited to year 2037 by theory? Probably something to do with 32bit or 64bit issue. Anyway, i have to deal a workaround for setting future dates (ex: 12/31/2111), unless if you guys have any solution using PHP's core date object / function.
Please do let me know if you find this problem interesting & have a good solution for this.
Thanks
Yamin
__._,_.___
Visit phpXperts website at www.phpxperts.net
.
__,_._,___
No comments:
Post a Comment