Wednesday, January 18, 2012

How to handle dates beyond 2037

$date = '2040-02-01';
$format = 'l d F Y H:i';
$mydate1 = strtotime($date);
echo '

', date($format, $mydate1), '

';


you’ll see “Wednesday 1 February 2040 00:00″ displayed in your browser. If you’re seeing a date in the late 60′s or early 70′s, your PHP application may be at risk from the Y2K38 bug!

Fortunately, PHP introduced a new DateTime class in version 5.2 (experimental support was available in 5.1 and be aware that some methods were introduced in 5.3)…
view plainprint?


$date = '2040-02-01';
$format = 'l j F Y H:i';
$mydate2 = new DateTime($date);
echo '

', $mydate2->format($format), '

';

No comments:

Post a Comment