Reputation: 55
this portion of code is outputing 01/01/1970. is my code incorrect? i have only posted the relevant part because it is part of a json page. the table field is date format. thanks
date('d/m/Y',$row['destroy_date'])
Upvotes: 1
Views: 11271
Reputation: 18859
this portion of code is outputing 01/01/1970. is my code incorrect?
That depends on what is in $row['destroy_date']. If that's actually a date, you have to convert it to a timestamp first (strtotime). If it's null or 0, it converts to Epoch (1-1-1970).
I've found DateTime a lot easier to use;
$datetime = new DateTime( $row['destroy_date'] );
echo $datetime->format( 'd-m-Y' );
Upvotes: 1
Reputation: 361
probably value into $row['destroy_date']
are null or incorrect for data formatting, check value with echo $row['destroy_date'];
Upvotes: 0
Reputation: 91963
If $row['destroy_date']
is not a UNIX timestamp, parse it with strtotime first:
date('d/m/Y', strtotime($row['destroy_date']))
Read in the manual for date and you'll see that the second argument cannot be a date in any format.
Upvotes: 11