svicino
svicino

Reputation: 173

How to handle date format in PHP

I am bringing in events via 3rd party API and processing them with PHP. I cannot figure out how to handle the date: /Date(-62135568000000-0800)/

I assumed it was an Epoch date, however when I processed it PHP was processing the date 100+ years in the future.

<?php
preg_match('/\d{12}-\d{4}/',$date_string, $date);
return date('U', strtotime(substr($date[0],0, 12);
?>

Upvotes: 2

Views: 87

Answers (1)

svicino
svicino

Reputation: 173

Thanks to @John Conde I figured it out;

preg_match('/\d{12}-\d{4}/',$date_string, $date);
return date('U', substr($date[0],0, 12)/1000);

Upvotes: 2

Related Questions