0

I have this json_ecoded data and I can not figure out how to convert this

'firstInvoiceDate' => string '/Date(1363824000000+0000)/' (length=26) 

back to

'firstInvoiceDate' => string '3/21/2013' 

I have tried date() and strtotime() but get the wrong results.

Any help would be greatly appriciated.

u_mulder
  • 54,101
  • 5
  • 48
  • 64
Artful_dodger
  • 698
  • 2
  • 7
  • 26
  • In the question title you specify +0100. Is this also something you need to deal with? – trincot Jan 31 '16 at 15:09
  • http://stackoverflow.com/questions/16749778/php-date-format-date1365004652303-0500 – Niklesh Raut Jan 31 '16 at 15:20
  • 1
    Thank you Wouter for taking the time to read my question I did read the question ' Convert Json date string to JavaScript date object' but my question is about how to resolve the issue in php and not javascript – Artful_dodger Jan 31 '16 at 22:20
  • Thank you LearningMode I did a search for this for some reason did not get any meaningful results but yours is the best answer for my project cheers M8 – Artful_dodger Jan 31 '16 at 22:23

1 Answers1

0

You could use this function:

function convertToDate($d, $format = 'm-d-Y') { 
    // First argument should have format like '/Date(1363824000000+0000)/'
    if (!preg_match("/[\d+-]+/", $d, $matches)) return null;
    return gmdate($format, $matches[0]/1000);
}

Call it like this:

print convertToDate('/Date(1363824000000+0000)/', 'm-d-Y');

Output:

03-21-2013

trincot
  • 317,000
  • 35
  • 244
  • 286