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