Reputation: 4319
Getting the time from a Wordpress post (the field being post_date_gmt stored in DATETIME), how can I convert that information (e.g 2011-03-23 20:28:26) to an actual, maleable date in PHP? (like Thursday, March 23rd, 2011)
Upvotes: 0
Views: 1611
Reputation: 30103
Use
date(formatString, yourDate)
or
gmdate(formatString, yourDate)
format string example: 'D, d M Y H:i:s T'
Upvotes: 0
Reputation: 254916
echo date('r', strtotime($datetime));
echo date('r', strtotime('2011-03-23 20:28:26'));
echo date('l, F jS, Y', strtotime('2011-03-23 20:28:26'));
See date()
for more formatting options.
Upvotes: 3
Reputation: 24969
You can use strtotime
or the DateTime
class.
// Using strtotime
$date = strtotime($row['post_date_gmt']);
// Using the DateTime class
$date = new DateTime($row['post_date_gmt']);
Because the date is in GMT and you're server most likely isn't, it may be wise to specify the time zone as well. Here's an example using DateTimeZone
.
$timezone = new DateTimeZone('UTC');
$date = new DateTime($row['post_date_gmt'], $timezone);
Upvotes: 1