Reputation: 12327
Im trying to convert my timestamp to a readable date (going to be used in a sql query).
My code:
$date1 = date("d-m-Y",Input::get('van'));
return Input::get('van')." ".$date1;
The timestamp:
1451602800000
the result
15-12-1966
When i try this application the result of that timestamp is Thu, 31 Dec
2015 23:00:00 GMT
Which is what i was expecting. What am i doing wrong that makes me get the wrong day-month year? the timestamp seems to be oke the code is the accepted answer here:
Adding:
date_default_timezone_set('UTC');
dosn't change anything
Upvotes: 0
Views: 82
Reputation: 748
Remove three zeros from the right of your timestamp. A Unix timestamp is represented in seconds, not milliseconds.
$date1 = date('d-m-Y', Input::get('van') / 1000);
return Input::get('van') . ' ' . $date1;
See the time function for an example of an acceptable timestamp that can be used with the date function.
Upvotes: 1
Reputation: 29
You probably use Laravel, so this package it integrated:
https://github.com/briannesbitt/Carbon
And try this tutorial to get up to speed:
https://scotch.io/tutorials/easier-datetime-in-laravel-and-php-with-carbon
Upvotes: 0