Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP strtotime returns a 1970 date when date column is null

I want to display $row->depositdate in dd-mm-yyyy format.

If the date column in database is null the date displayed is : 01-01-1970

echo "<td align=center>".date('d-m-Y', strtotime($row->depositdate))."</td>";

If the date is null in database it should display nothing , otherwise the date in dd-mm-yyyy format should be displayed.

Thanks in advance

Sandeep

like image 495
Sandy505 Avatar asked Oct 12 '11 08:10

Sandy505


1 Answers

NULL is interpreted as 0 by strtotime, since it want to be passed an integer timestamp. A timestamp of 0 means 1-1-1970.

So you'll have to check for yourself if $row->depositdate === NULL, and if so, don't call strtotime at all.

like image 83
GolezTrol Avatar answered Sep 24 '22 18:09

GolezTrol