Notes Ninjas Notes Ninjas
Lotus Notes hints, tips, error messages
RFC882 Date format function for Lotus Notes XML and RSS

Hint Short Cut: Add this to your code & documentation to help you find this page.
http://www.notesninjas.com/#RFC882dates or http://www.notesninjas.com/A555F9/nn.nsf/ByAlias/RFC882dates


Converting from notes date items to RFC-882. Here's the code.





 

NB: year can be 2 or 4 digits.

The RFC882 standard is here: http://www.w3.org/Protocols/rfc822/

Here is the code:

Function RFC882Date(Byval dateval As Variant) As String
 ' See http://www.notesninjas.com/A555F9/nn.nsf/ByAlias/RFC882dates

On Error Goto ErrHdlr
RFC882Date=""

'if empty return nothing
If Cstr(dateval)="" Then Goto LeaveSub


Dim dow(7) As String
dow(1)="Sun"
dow(2)="Mon"
dow(3)="Tue"
dow(4)="Wed"
dow(5)="Thu"
dow(6)="Fri"
dow(7)="Sat"

Dim mon(12)
mon(1)="Jan"
mon(2)="Feb"
mon(3)="Mar"
mon(4)="Apr"
mon(5)="May"
mon(6)="Jun"
mon(7)="Jul"
mon(8)="Aug"
mon(9)="Sep"
mon(10)="Oct"
mon(11)="Nov"
mon(12)="Dec"

RFC882Date = dow(Weekday(dateval)) & ", " & Day(dateval) & " " & _
mon(Month(dateval)) & " " & Right(Cstr(Year(dateval)),2) & _
" " & Right("0" & Hour(dateval),2) & ":" & Right("0" & Minute(dateval),2)  & _
":" & Right("0" & Second(dateval),2) & " GMT"


LeaveSub:
Exit Function

ErrHdlr:
RFC882Date=""
Resume LeaveSub
End Function

How to use it:

either simply use it with the document's lastModified property:

print "<Last_Modified>" & rfc882date(doc.lastmodified) & "<Last_Modified>"

or for a Notes item that stores a date time value:

dim ni as notesitem

dim ndt as notesdatetime

If doc.HasItem("LastSaved") Then
   Set ni = doc.GetFirstItem("LastSaved")
   Set ndt = ni.DateTimeValue  
   Print "<LAST_SAVED>" & RFC882Date(ndt.lslocaltime) & "</LAST_SAVED>"
End if

Sometimes LSGMTTime instead of lslocaltime gives better results....

If you are storing dates in text values, (oh dear, please don't), you need to convert it to a date time first, there are some helpful tips here:

http://www.notesninjas.com/A555F9/nn.nsf/ByAlias/NotesDateTime

Let me know if there are problems.

Time zone problems

The time zone can cause problems. You can use LSGMTTime instead of lslocaltime or put in a timezone modifier.

One way to sort this out is to put this code before the main :

 

 Dim session As New NotesSession
Dim inter As NotesInternational
Set inter = session.International

If inter.TimeZone=0 Then
 tzone=""
Elseif (inter.timezone>0) Then
 tzone="-" & Right$("0" & inter.TimeZone,2) & ":00"
Else
 tzone="+" & Right$("0" & -inter.TimeZone,2) & ":00"
End If

and add tzone to the end of the string :

RFC882Date = dow(Weekday(dateval)) & ", " & Day(dateval) & " " & _
mon(Month(dateval)) & " " & Right(Cstr(Year(dateval)),2) & _
" " & Right("0" & Hour(dateval),2) & ":" & Right("0" & Minute(dateval),2)  & _
":" & Right("0" & Second(dateval),2) & " GMT"
& tzone

 

 

 Jump to:     Notes Tips
    Lotus Notes Index 
  Register for Tips
Previous Lotus Notes Tip 
    Next Lotus Notes Tip
Your company logo here?
Adam Foster
Free Cash Making Web Site
Free Revenue Earning Blog Site
 Free Revenue Earning Newsletter Site   
Free Search Pages Free Web stats
Free Contact Us page
Cheap .com domain names
 Need a website or 
   Lotus Notes
  problem solved?
Adam Foster
Lotus Notes and Domino 6 Programming Bible by Brian Benz, Rocky Oliver
Covers all the programming techniques, concepts, and languages used with Notes and Domino, as well as the many new features of Domino 6 Thoroughly examines the Notes and Domino role with Java, XML, Web services, and other IBM products and technologies Provides extensive code and examples, many geared to the needs of administrators High-profile authors, known to their audience through conferences and articles Companion Web site shows example applications from the book running on a live Domino server and provides code download.
See at: Amazon.co.uk | Amazon.com |