On Thu, 2010-01-14 at 13:14 -0500, John Taylor-Johnston wrote:

> Hello,
> 
> In a mysql date() field, I set the default to "0000-00-00".
> 
> Therefore, $mydata->birthday = "0000-00-00";
> 
> But when I run this next line, $then = 1969.
> 
> $then=date("Y", strtotime($mydata->birthday));
> 
> Why 1969, and not 0 or nothing?
> 
> If I  echo strtotime("0000-00-00");
> 
> Nothing appears. So $then should be nothing?
> 
> What is wrong with my logic?
> 
> Thanks,
> John
> 


MySQL uses a default "0000-00-00" value for date fields generally, but
when converted into a timestamp, the string equates to a false value. In
PHP, timestamps are numerical values indicating the seconds since
Midnight of the 1st January 1969. As PHP uses loose data typing, false
is converted to a 0 (zero),and strtotime("0000-00-00") returns false. As
such, it is treated as the date when time began (for the PHP date object
at least).

There's nothing wrong with your logic, but if you want to check for
empty values, then you should use an extra if statement to check if
strtotime("0000-00-00") === false

Thanks,
Ash
http://www.ashleysheridan.co.uk


Reply via email to