-3

Date Format using PHP

Input date is '1568145593000', i need to convert into m-d-y format using php

Anyone knows how to convert this? Thanks =).

Vincy Joseph
  • 223
  • 1
  • 3
  • 15
  • That input date is not in the format you specified. It looks more like a timestamp with milliseconds, which would evaluate to '2019-09-10 15:59:53' – aynber Jul 06 '21 at 19:18
  • 2
    **1568145593000** this is timestamp in milliseconds, so all you need to do is `/ 1000` to get the seconds and can pass it to `date` method like this `date('m-d-y', $timestampMs/1000);` – Haridarshan Jul 06 '21 at 19:19

1 Answers1

1
echo date('m-d-Y', 1568145593000 / 1000);

Divide the timestamp by 1000 to get the timestamp in seconds.

See:

PHP date https://www.php.net/manual/en/function.date.php and for the formatting characters: https://www.php.net/manual/en/datetime.format.php (scroll down a bit)

whoshotdk
  • 286
  • 2
  • 14