Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Exclamation outputting a date from a db into a specific format?

    Hi All,

    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
    Code:
    <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
    PHP Code:
        <item> 
        <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>
        </item>
    its the pubDate i am trying to format.

    any ideas please
    thanks
    Luke

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    http://php.net/manual/en/function.date.php

    Easy answer

    PHP Code:
    <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.

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    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.
    many thanks

    p.s the link to my validator of my rss is here

    might provide some answers
    cheers

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Did you use strtotime?

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    no mate because 'i think' 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

    cheers
    Luke

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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

    PHP Code:
    <pubDate><?php echo date("D, d M Y. G:i:s"strtotime($row['datestamp'])))?></pubDate>

  • Users who have thanked Keleth for this post:

    LJackson (06-24-2010)

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    ok used strtotime and it now shows the correct date thanks but still wont accept the date as a valid pubDate here is the page which says what is ok to use

    http://feedvalidator.org/docs/error/...C2822Date.html

    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?

    many thanks
    Luke

    edit sorry should of looked first need to add a T
    Last edited by LJackson; 06-24-2010 at 10:45 PM.

  • #8
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    So its working now?

  • #9
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    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'

    any ideas?

    many thanks
    Luke

    p.s here is the validator results
    http://feedvalidator.org/check.cgi?u...scount_rss.php see if you can see what isnt right with the pubDate

    appreciate it!!!

  • #10
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    ok mate it now validates 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
    Code:
    <?php echo '<?xml version="1.0" encoding="UTF-8"?>';?>
    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
    what can i do to resolve that issue? many many thanks mate for your continued support

  • #11
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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.

  • #12
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Sorry, donno enough about RSS feeds to answer your last question.

  • #13
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •