note 94466 added to function.strtotime

From: Date: Fri, 06 Nov 2009 17:54:14 +0000
Subject: note 94466 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-162460@lists.php.net to get a copy of this message
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); } ---- Server IP: 64.71.164.2 Probable Submitter: 64.244.102.2 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/94466 Del: integrated -- https://master.php.net/note/delete/94466/integrated Del: useless -- https://master.php.net/note/delete/94466/useless Del: bad code -- https://master.php.net/note/delete/94466/bad+code Del: spam -- https://master.php.net/note/delete/94466/spam Del: non-english -- https://master.php.net/note/delete/94466/non-english Del: in docs -- https://master.php.net/note/delete/94466/in+docs Del: other reasons-- https://master.php.net/note/delete/94466 Reject -- https://master.php.net/note/reject/94466 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162460) next »