Chris P
Chris P

Reputation: 2357

php convert datetime

Well i take from my database table something like:

$datetime="2012-01-12 00:00:00" i want to convert this variable/info to something like Mon, 02 Jan 2012 16:40:39 GMT I want to put this info into my rss feed <pubDate></pubDate>

Upvotes: 1

Views: 11252

Answers (3)

user656925
user656925

Reputation:

Converting from human readable to machine readable to human readable again is not efficient. If possible store as a Unix Timestamp and just use date()

Upvotes: 0

craig1231
craig1231

Reputation: 3867

Be careful with timezones though...

$tm = date("r", strtotime($datetime));
echo "<pubDate>".$tm."</pubDate>";

Upvotes: 0

Tim Withers
Tim Withers

Reputation: 12059

You could try this:

$datetime="2012-01-12 00:00:00";
$time=strtotime($datetime);
echo date("r",$time);

-or-

echo date("D, d M Y H:i:s T",$time);

Upvotes: 8

Related Questions