note 106916 added to function.checkdate

From: Date: Mon, 19 Dec 2011 07:23:38 +0000
Subject: note 106916 added to function.checkdate
Groups: php.notes 
Request: Send a blank email to php-notes+get-185124@lists.php.net to get a copy of this message
don't use strtotime() to format inputs to checkdate(). It would give false results. Eg, Below function would return true though it should have been false $str = '2011-11-31'; //invalid date, november has 30 days only function isDateValid($str) { $stamp = strtotime($str); if (!is_numeric($stamp)) return FALSE; //checkdate(month, day, year) if ( checkdate(date('m', $stamp), date('d', $stamp), date('Y', $stamp)) ) { return TRUE; } return FALSE; } The reason is that strtotime() coverts 2011-11-31 to 2011-12-01. check with date('Y-m-d', strtotime('2011-11-31')) ---- Server IP: 69.147.83.197 Probable Submitter: 49.14.144.65 ---- Manual Page -- http://www.php.net/manual/en/function.checkdate.php Edit -- https://master.php.net/note/edit/106916 Del: integrated -- https://master.php.net/note/delete/106916/integrated Del: useless -- https://master.php.net/note/delete/106916/useless Del: bad code -- https://master.php.net/note/delete/106916/bad+code Del: spam -- https://master.php.net/note/delete/106916/spam Del: non-english -- https://master.php.net/note/delete/106916/non-english Del: in docs -- https://master.php.net/note/delete/106916/in+docs Del: other reasons-- https://master.php.net/note/delete/106916 Reject -- https://master.php.net/note/reject/106916 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#185124) next »