Matarishvan
Matarishvan

Reputation: 2432

How to convert 13 digit string to date of format d-m-Y in PHP

I am having problems converting 13 digit string to date which should have following format m-d-Y.
This is my 13 digit date string - 1415855073164

I have tried this.

$date123 = $rawDataPopup[$i]['datetime'];   //1415855073164
$convertFromDate=($date123 )/1000; // dividing by 1000 which gives me 10 digit string.

What to do next to get m-d-Y date format.

Upvotes: 0

Views: 3848

Answers (1)

doublesharp
doublesharp

Reputation: 27657

You just need to pass the unix epoch timestamp (seconds since 1/1/1970) to the PHP date( $format, $timestamp ) function.

$tsSeconds = $rawDataPopup[$i]['datetime'] / 1000;
date( 'Y-m-d', $tsSeconds );

Upvotes: 3

Related Questions