Solved

Formatting time in an RSS feed

Posted on 2009-05-17
7
279 Views
Last Modified: 2013-12-12
I am creating a custom RSS feed using the <dc:date> field to display event dates. The dates and times are split up in the database and I am having troubles getting them to display properly  in the feed. The StartDate is fine - I just need to add the vcalStartTime field so the time shows up. Or have no time at all show up.

I think I need to somehow use the $newdate2 value (see code snippet) but when I add it to my $date I get the issue where all dates and times are set to Dec 31 1969 (so its wrong). If I remove the time value from the date() I still get a 5:00 AM time on everything.

Any suggestions are appreciated!
Thanks!

$newdate2 = $feed['StartDate'] . T . $feed['vcalStartTime'] .Z  ;
 
 
$date = explode("-", $feed['StartDate']); 
list($year, $month, $day) = $date;
echo "<dc:date>" . date("D, j M Y H:i:s T", strtotime("$month/$day/$year")) ."</dc:date>\n";

Open in new window

0
Comment
Question by:SashaIsaac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24407396
Not sure what the formats are for these $feed[] fields, so let's assume that they are ISO8601-compliant.

Check the man pages here:
http://www.faqs.org/rfcs/rfc2822
http://cyber.law.harvard.edu/rss/rss.html#requiredChannelElements
http://us2.php.net/manual/en/function.date.php

HTH, ~Ray
$iso_date = $feed['StartDate'] . T . $feed['vcalStartTime'];
$pubDate = date('r', strtotime($iso_date));

Open in new window

0
 

Author Comment

by:SashaIsaac
ID: 24407671
I think I was missing the use of date('r) - I checked some of the resources you linked to as well. Now I have my date and time almost correct - just off by 1 hour. I am trying to add that hour and then I will post the final solutions.

Thanks for that help! Much appreciated.
0
 

Author Comment

by:SashaIsaac
ID: 24407721
Although I think I need to check my formatting of my date somewhere - when I go to validate it says dc:date needs to be the W3CDTF format (which I believe is ISO8601 too). So I'll check into why that is not in that format. Thanks!
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 110

Expert Comment

by:Ray Paseur
ID: 24407824
Yes, the W3CDTF is ISO8601-compliant.  I think that is PHP date('c');  That is different from the RSS standard for pubDate.

One possibility if the time is off by an hour is that your serer is in a different timezone.  That happens to me.  I am in Washington, DC and my servers are in Chicago.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 24407830
An ISO 8601 DATETIME with an added hour...
date('c', strtotime($iso_date . ' + 1 hour'));

Open in new window

0
 

Author Comment

by:SashaIsaac
ID: 24408068
I hadn't added the 'c' to the other line in my code:

echo "<dc:date>" . date("D, j M Y H:i:s T", strtotime("$month/$day/$year")) ."</dc:date>\n";


I am including the solution - thanks again for the assistance!
$iso_date = $feed['StartDate'] . T . $feed['vcalStartTime'] ;
$newdate3 = date('c',strtotime($iso_date . '+ 1 hour' ));	
 
//in the channel/item		
 
echo "<dc:date>" . date("c", strtotime("$newdate3")) ."</dc:date>\n";

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 24408253
Just a thought, ... $newdate3 is already in date('c') format so you do not need to use strtotime() and re-convert it.

Thanks for the points - it's a great question, ~Ray
$iso_date = $feed['StartDate'] . T . $feed['vcalStartTime'] ;
$newdate3 = date('c',strtotime($iso_date . '+ 1 hour' ));       
 
//in the channel/item           
 
echo "<dc:date>$newdate3</dc:date>\n";

Open in new window

0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question