开发者

date code in php displaying 01/01/1970

开发者 https://www.devze.com 2023-03-10 18:33 出处:网络
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. 开发者_Python百科the table field is date format. thanks

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. 开发者_Python百科the table field is date format. thanks

date('d/m/Y',$row['destroy_date'])


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.


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' );


probably value into $row['destroy_date'] are null or incorrect for data formatting, check value with echo $row['destroy_date'];

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号