Really Simple Syndication at Last!

The use of RSS has finally come to Wicked Strategery!

Since WS is XML driven, I wrote a script to create the RSS feed automatically, much like the rest of the site. However, this was not without its own problems.

Problems?

The first problem is deciding what version of RSS to support. I opted to go with 2.0, as opposed to 0.92 or 1.0. It was just as easy to implement one particular version over another. And eventually, I might get around to implementing those other versions, so a choice is available.

Secondly, ASP does not have a nice, clean-cut function for the formatting of dates and times. And no easy way to get a date/time into RFC 882 formatting, as required by RSS.

Solution

I wrote this function to accept a date/time and format it as a RFC 882 compliant string. It's really easy to use, and gets the job done.

Usage: The function accepts a DateTime value and a string representing the timezone offset (-0500 for EST).

The RFC822 standard mandates that the time/date values be 0-padded, and that is what the zeroPad function accomplishes. It accepts a string to pad, and a desired length. For example, zeroPad("2", 4) would return "0002".

Code

Function zeroPad(m, t)
  zeroPad = String(t - Len(m), "0") & m
End Function
 
Function RFC822(TimeDate, offset)
  If IsDate(CDate(TimeDate)) Then
    TimeDate = CDate(TimeDate)
    RFC822 = WeekdayName(Weekday(TimeDate), True) & ", " & _
      zeroPad(Day(TimeDate), 2) & " " & _
      MonthName(Month(TimeDate), True) & " " & _
      Year(TimeDate) & " " & _
      zeroPad(Hour(TimeDate), 2) & ":" & _
      zeroPad(Minute(TimeDate), 2) & ":" & _
      zeroPad(Second(TimeDate), 2) & " " & _
      CStr(offset)
  Else
    RFC882 = ""
  End If
End Function

There you have it, a function to format a date/time as RFC 822 format.



Tags

  • Active Server Pages
  • www.dougjenkinson.net

Revisions

  • 1/22/2012 - Archived.
  • 12/24/2005 - Included the zeroPad function and better usage information.
  • 9/2/2005 - Article published.