Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert PHP datetime to MySQL RFC-822 valid Date-Time for RSS Feed

Tags:

php

mysql

rss

I want to add a date/time, created in PHP, to MySQL that is valid in a RSS Feed.

I'm using in PHP

$d = date( 'Y-m-d H:i:s T', time() );
$mysqldate = gmdate(DATE_RSS, strtotime($d));

inserting that into a DATETIME field in my database

But it saves it in this format Wed, 02 Oct 2002 08:00:00

and it need to be in this format to be RFC-822 valid Wed, 02 Oct 2002 08:00:00 EST

like image 777
daihovey Avatar asked Sep 03 '25 01:09

daihovey


2 Answers

Use DATE_RFC822 instead of DATE_RSS

like image 60
Long Ears Avatar answered Sep 04 '25 16:09

Long Ears


Why are you converting a php date time to a string, then converting that string back into a datetime object again? that's a serious waste of cpu cycles. why not simply do

$mysqldate = gmdate(DATE_RSS, time())?

as well, gmdate generates a UTC timestamp, for which there is no timezone - it's always GMT+0

like image 43
Marc B Avatar answered Sep 04 '25 17:09

Marc B