By Brian, 1 year and 11 months ago

RFC-32 Date Formatting with Classic ASP

Tonight I was working on an RSS package for a client of mine. Having dealt with RSS feeds in the past, I figured it wouldn't be a big deal. However, my experience with them has always been on the 'receiving' end of it, imploding out the <item></item>'s and making sense of the xml.

For the most part, setting up the RSS2.0 feed was pretty straight forward. The one thing that took a little time to manipulate was the RFC-32 date/time formatting that RSS Feeds require in order to validate. And we all know how important validation is :)

So, I came up with a simple little function to help you out and save you some time in your own Classic ASP RSS feeds.

  1. < %
  2. Function getrfcdate(mydate)
  3.   'format date in rfc-32
  4.   'format:  Wed, 02 Oct 2002 08:00:00 EST
  5.  
  6.   If Hour(mydate)< 10 Then
  7.     myhour = "0" & Hour(mydate)
  8.   Else
  9.     myhour = Hour(mydate)
  10.   End If
  11.  
  12.   If minute(mydate)< 10 Then
  13.     myminute = "0" & minute(mydate)
  14.   Else
  15.     myminute = minute(mydate)
  16.   End If
  17.  
  18.   If second(mydate)< 10 Then
  19.     mysecond = "0" & second(mydate)
  20.   Else
  21.     mysecond = second(mydate)
  22.   End If
  23.  
  24.   If day(mydate)< 10 Then
  25.     myday = "0" & day(mydate)
  26.   Else
  27.     myday = day(mydate)
  28.   End If
  29.  
  30.   mymonth = monthName(Month(mydate),true)
  31.  
  32.   myyear = Year(mydate)
  33.  
  34.   dayname = WeekdayName(Weekday(mydate),true)
  35.  
  36.   mydate = dayname & ", " & myday & " " & mymonth & " " & myyear & " " & myhour & ":" & myminute & ":" & mysecond & " EST"
  37.  
  38.   getrfcdate = mydate
  39. End Function
  40.  
  41. %>

To call it, simply pass in a normal date/time string, such as now() or a getdate() recordset variable return from a sql query:

  1. < %
  2. response.write "<pubDate>"& getrfcdate(now()) &"</pubDate>" & vbcrlf
  3. %>

There you go :)

2 comments

Gravatar #1. gabru
1 year and 3 months ago

here is a complete ready to use RSS component for classic asp http://www.webdevbros.net/2007/07/01/asp-vbscript-rss-readerwriter-class/

Gravatar #2. Brian Cummiskey
1 year and 3 months ago

Gabru, that's a neat package you got there. I will check it out further for sure! Thanks!

Write a comment

If you want to add your comment on this post, simply fill out the next form:





* Required fields

You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>.

No trackbacks

To notify a mention on this post in your blog, enable automated notification (Options > Discussion in WordPress) or specify this trackback url: http://​skeymedia.com/​rfc-32-date-formatting-with-classic-asp/​trackback/