Reputation: 781
How do I format this str coming from a database to something more readable.
2012-04-06T10:55:58-07:00
I would like it in the format of m-y. I have tried
$date = date('m-y',strtotime('2012-04-06T10:55:58-07:00'));
I am stumped.
Thanks!
Upvotes: 0
Views: 240
Reputation: 30394
If the time zone isn't meaningful you can chop it off like this:
$dbDateString = '2012-04-26T10:55:58-07:00';
$dateString = substr($dbDateString, 0, 10);
$date = date('m-y',strtotime($dateString);
or you can go the cheap route:
$dbDateString = '2012-04-26T10:55:58-07:00';
$year = substr($dbDateString, 0, 4);
$month = substr($dbDateString, 5, 2);
Upvotes: 1
Reputation: 11552
Check out: How do I convert an ISO8601 date to another format in PHP?
They solution they provided was:
$date = '2011-09-02T18:00:00';
$time = strtotime($date);
$fixed = date('l, F jS Y \at g:ia', $time); // 'a' is escaped as it's a format char.
Upvotes: 0