note 84085 added to function.strtotime

From: Date: Thu, 26 Jun 2008 22:50:44 +0000
Subject: note 84085 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-140855@lists.php.net to get a copy of this message
Alex, it will return false for a null date. // reading from my login tracking table (MySQL) $db_content = myconnect(PRIVATE_LOGIN,PRIVATE_PASSWORD); $sql = "SELECT * FROM keys"; $sql .= " WHERE login='".$_SESSION['login']."'"; $sql .= " AND password='".$_SESSION['password']."';"; $result = mysql_query($sql, $db_content) or die(mysql_error()); if ($result){ $row=mysql_fetch_array($result); $date_expire = $row['date_expire']; if( !strtotime($date_expire) ){ // false if bad date ... fix the problem here ... } ... } Please note that this DOES NOT cover the cases where strtotime() has guessed at what was intended in $date_expire. To protect yourself you can also check that the date as converted actually matches the date strtotime() thinks that you want: $x = date("Y-m-d",strtotime($date_expire)); if($x !== $date_expire){ // bad conversion ... do something to fix the problem here ... } >>BEWARE: Someone thought this was a good idea... >>$t = strtotime('2008-00-14'); // == 1197590400 >>$d = date("d-m-Y", $t); // == 14-12-2007 >>I am not sure when this function EVER returns false but its >>obviously not when the >>dates incorrect. ---- Server IP: 64.71.164.2 Probable Submitter: 71.127.77.132 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/84085 Del: integrated -- https://master.php.net/note/delete/84085/integrated Del: useless -- https://master.php.net/note/delete/84085/useless Del: bad code -- https://master.php.net/note/delete/84085/bad+code Del: spam -- https://master.php.net/note/delete/84085/spam Del: non-english -- https://master.php.net/note/delete/84085/non-english Del: in docs -- https://master.php.net/note/delete/84085/in+docs Del: other reasons-- https://master.php.net/note/delete/84085 Reject -- https://master.php.net/note/reject/84085 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140855) next »