View Full Version : outputting a date from a db into a specific format?
06-24-2010, 11:03 PM
i have some date/time data stored in my db as date/time fields and an example of the data would be 2010-06-24 21:30:43 for example
now i have set up an rss feed which allows for a pubDate to be set but it only allows a date/time in the following format
<pubDate>Wed, 02 Oct 2002 13:00:00 GMT</pubDate>
so i have my xml file which pulls data from the db to create the feed but i am having trouble formatting my date/time data into the above format :(
i have found out that i need to use this format
("D, d M Y. G:i:s")
but i have o idea how to apply that to my data
here is my php code
<title><?php echo $row['codeID']?></title>
<description><?php echo htmlspecialchars_decode($description)." from $name";?></description>
<pubDate><?php echo $row['datestamp'])?></pubDate>
<link><?php echo htmlentities($row['codeLink'])?></link>
its the pubDate i am trying to format.
any ideas please
06-24-2010, 11:10 PM
Easy answer :p
<pubDate><?php echo date("D, d M Y. G:i:s", $row['datestamp']))?></pubDate>
If datestamp is not a timestamp (seconds from epoc), just use strtotime to convert it to such.
06-24-2010, 11:28 PM
Hi mate, thanks for your help.
however i am still unable to get my feed to recognise it as a valid pubDate plus the fact that it is giving out an incorrect date.
the date in my db is 2010-06-24 22:24:00
but the formatting is giving out <pubDate>Thu, 01 Jan 1970 00:33:30</pubDate>???
any ideas as to why this is.
p.s the link to my validator of my rss is here (http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.kernow-connect.com%2Frss_feeds%2Fdiscount_rss.php)
might provide some answers :D
06-24-2010, 11:31 PM
Did you use strtotime?
06-24-2010, 11:37 PM
no mate because 'i think' :D my datestamp is a timestamp? its field type in my db is date/time?
or at least i thought it was a timestamp, but im sure your gonna tell me otherwise :D
06-24-2010, 11:39 PM
Well, thats why I was specific about the seconds since epoc part. No, if you have a date time and anyone can read what the date/time is, its not the seconds from epoc :p
<pubDate><?php echo date("D, d M Y. G:i:s", strtotime($row['datestamp'])))?></pubDate>
06-24-2010, 11:42 PM
ok used strtotime and it now shows the correct date :D thanks but still wont accept the date as a valid pubDate here is the page which says what is ok to use
the only difference i can see is that my date/time doesnt have the GMT at the end would that matter? if so how do i get that?
edit sorry should of looked first :) need to add a T :D
06-24-2010, 11:46 PM
So its working now?
06-24-2010, 11:51 PM
GRRR still wont b****y accept it even though its now exactly as in the example :(
my date is now outputting as
Thu, 24 Jun 2010 22:24:00 BST
and the example says it must be like
Wed, 02 Oct 2002 08:00:00 EST
which is the same format?
why wont you just work 'picks laptop up and throws across the room' :)
p.s here is the validator results
http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.kernow-connect.com%2Frss_feeds%2Fdiscount_rss.php see if you can see what isnt right with the pubDate
06-25-2010, 12:04 AM
ok mate it now validates :D didnt like the BST timezone. so had to set it as GMT and it now likes it :)
p.s i get a warning about
Feeds should not be served with the "text/html" media type?
here is my code
<?php echo '<?xml version="1.0" encoding="UTF-8"?>';?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
what can i do to resolve that issue? many many thanks mate for your continued support :D
06-25-2010, 12:08 AM
Heh, the error its giving on the validation feed is not one of syntax... its one of "you've put a date in the future". The validation is showing 23:00 GMT... which is in the future. Check your code to make sure the RSS feed is outputting the current date in the right location. And if this is how you intend it to be, then its no problem.
06-25-2010, 12:10 AM
Sorry, donno enough about RSS feeds to answer your last question.
06-25-2010, 12:15 AM
yeah not sure why thats saying that, gotta be something to do with the timezone set because its displaying the correct data :)
and no worries mate, thanks for all you time and help on the above problems :)
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.