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

Anant Kumar Singh
  • 68,309
  • 10
  • 50
  • 94
Blake Rivell
  • 12,005
  • 28
  • 104
  • 208

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

Anant Kumar Singh
  • 68,309
  • 10
  • 50
  • 94
  • 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