-1

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

7
  • What is Input::get('van')? Commented Jul 5, 2016 at 23:30
  • Its the value (from a get request) holding the exact timestamp. it could be any var holding that timestamp value. Commented Jul 5, 2016 at 23:31
  • Well, your 1451602800000 timestamp is for June 18 in the year 47969. Commented Jul 5, 2016 at 23:32
  • Brogan is that the date you get when entering it in the provided link? I get Assuming that this timestamp is in milliseconds: GMT: Thu, 31 Dec 2015 23:00:00 GMT Commented Jul 5, 2016 at 23:33
  • The unix timestamp is in seconds. Commented Jul 5, 2016 at 23:34

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.