note 84085 deleted from function.strtotime by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 03:52:43 +0000 |
| Subject: | note 84085 deleted from function.strtotime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142096@lists.php.net to get a copy of this message | ||
Note Submitter: promotions at jdnash dot org
----
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.