note 94466 deleted from function.strtotime by derick

From: Date: Sun, 03 Nov 2013 15:22:02 +0000
Subject: note 94466 deleted from function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197411@lists.php.net to get a copy of this message
Note Submitter: kendsnyder at gmail dot com ---- Watch out when using strtotime() on a string that might begin with "0000-00-00" as MySQL stores "null" dates on a not-null date column. The value returned by strtotime("0000-00-00") varies by php version. Consider the following: <?php date('Y-m-d',strtotime('0000-00-00 00:00:00')); // returns "1969-12-31" on the following versions: // Win XP php 5.2.9-2 // Win 7 php 5.3.0 // RHEL 5 php 5.2.8 // but returns "-0001-11-30" on RHEL 5 php 5.2.10! // consider checking for "zero" dates. e.g.: function formatDate($format,$dateStr) { if (trim($dateStr) == '' || substr($dateStr,0,10) == '0000-00-00') { return ''; } $ts = strtotime($dateStr); if ($ts === false) { return ''; } return date($format,$ts); } ?>

« previous php.notes (#197411) next »