Reputation: 1643
Is it possible to convert this kind of string:
00:12:57 Nov 05, 2014 PST
To a proper date?
im using carbon for mysql timestamps, and i get this kind of format when i receive response from paypal api.
My initial thought was to explode it, and reformat it and then do the converting, but maybe there is another proper way to doing it?
without exploding it and doing such stuff, am i able to transform such format to a valid one so i can use it to store in mysql (timestamp)
Upvotes: 0
Views: 61
Reputation: 4305
You can use the DateTime class for this. For example:
$date = new DateTime('00:12:57 Nov 05, 2014 PST');
echo $date->format('Y-m-d');
Upvotes: 0
Reputation: 7540
$date = DateTime::createFromFormat("read doc",$string_var);
should help...(doc)
Upvotes: 0
Reputation: 1717
You can use strtotime()
to convert it to timestamp and then use date()
to format it like you want :
$timestamp = strtotime('00:12:57 Nov 05, 2014 PST');
echo date('Y-m-d H:i:s', $timestamp);
// 2014-11-05 03:12:57
Upvotes: 3