0

I am attempting to convert an epoch timestamp value to a formatted date string in PHP and getting unexpected results:

$dateStart = 1104555600000;
$formattedDate = date('Y-m-d', $dateStart);

Expected Result: 2005-01-01   
Actual Result: 1993-09-26

1104555600000 is equivalent to 2005-01-01

However, $formattedDate ends up being 1993-09-26

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Blake Rivell
  • 13,105
  • 31
  • 115
  • 231

1 Answers1

2

Actually you epoch timestamp is in millisecond, convert it to second and then convert it to date

<?php

$dateStart = 1104555600000;
echo $formattedDate = date('Y-m-d', $dateStart/1000);

Output:- https://eval.in/981417

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
  • how come the divided by 1000 is not working when passing an epoch timestamp such as: 4307486400000 which should be year 2160? Instead it is converting to year 1970. – Blake Rivell Apr 05 '18 at 18:18