I am needing to convert a last updated date on a document to the ISO 8601 format (YYYY-MM-DDThh:mm:ssTZD) … so “11/07/2003 02:00:49 PM CST” formatted to “2003-11-07T14:00:49-6:00” … any one have any ideas how I can do this?
Subject: Converting a date to ISO 8601
Since there is no such formatting option available in the date field formatting options, you’ll have to build a display field yourself as text.
Subject: RE: Converting a date to ISO 8601
If it’s LotusSCript you want, try this:
Function DateTimeToXMLFormat(vDT As Variant) As String
Const DTFORMAT = "YYYY-MM-DDThh:mm:ss"
Dim dt As New NotesDateTime(vDT)
Dim strDTPart As String
Dim strTZPart As String
strDTPart = Format$(dt.LSLocalTime, DTFORMAT)
If dt.TimeZone < 0 Then
strTZpart = Format$(dt.TimeZone, "00") & ":00"
Else
strTZPart = "+" & Format$(dt.TimeZone, "00") & ":00"
End If
DateTimeToXMLFormat = strDTPart & strTZPart
End Function
Subject: RE: Converting a date to ISO 8601
11 years later is still actual ![]()
I think your code has a bug with ±. According to ISO 8601/RFC 3339,
1996-12-19T16:39:57-08:00 is equivalent to
1996-12-20T00:39:57Z
So updated function will be:
Function dateTimeToISO8601( vDT as variant ) as String
Dim dt As New NotesDateTime( vDT )
Dim strDTPart As String
strDTPart = Format( dt.LSLocalTime, {YYYY-MM-DDThh:mm:ss} )
Dim timeZone As Integer
timeZone = - dt.Timezone
Dim strTZPart As String
strTZPart = Format( timeZone, "00" ) & ":00"
If timeZone >= 0 Then
strTZpart = "+" & strTZpart
End If
dateTimeToISO8601 = strDTPart & strTZPart
End Function
Another problem is how to deal with, for example, New Delhi’s time zone UTC+05:30? NotesDateTime doesn’t support half-hour zones.