Domino on Linux/Unix, Troubleshooting, Best Practices, Tips and more ...

 
alt

Daniel Nashed

 

ISO 8601 date format in Lotus Script

Daniel Nashed  2 October 2021 17:39:22

ISO 8601 date format isn't a new requirement but there isn't an implementation yet -- but there is an AHA idea.

Took me a moment to write conversion function. None of the date format functions helped.

The format string always appended the "GMT" string.


The tick is to use a NotesDateTime first to ensure you can convert into GMT.

In the next step LSGMTTime is important to convert the date to a normal Date (as a Variant ..).

Finally craft your own date string using the Format function for leading zeros..


-- Daniel


------------------


Update 3.9.2021: Lars came up with an easier way. I am not sure why I always had "GMT" added to my string when I tested with the Format function.

Here is a more simple way from Lars Berntrop-Bos:

Function ISO8601Date(dateTime As NotesDateTime) As String

  ISO8601Date = Format$(dateTime.LSGMTTime, "yyyy\-mm\-dd\Thh\:nn\:ss\Z")

End Function


Thanks Lars! This makes it more simple and this is why posting solutions make sense. Someone in the community might come up with a better solution! Cool thanks!

-- Daniel

------------------


Example:
2021-09-20T01:02:03Z

Function ISO8601Date (dateTime As NotesDateTime) As String


 Dim gmt As Variant

       
 gmt = dateTime.LSGMTTime

 ISO8601Date =  Format (Year (gmt),"0000") + "-" + Format (Month (gmt),"00") + "-" + Format (Day (gmt),"00") + "T" + Format (Hour (gmt),"00") + ":" + Format (Minute (gmt),"00") + ":" + Format (Second (gmt), "00") + "Z"

       
End Function


Comments

1Richard Moy  02.10.2021 23:13:52  ISO 8601 date format in Lotus Script

We only been working with the GMT format when interacting with the browser

2Lars Berntrop-Bos  03.10.2021 13:21:43  ISO 8601 date format in Lotus Script

somewhat shorter:

Function ISO8601Date(dateTime As NotesDateTime) As String

ISO8601Date = Format$(dateTime.LSGMTTime, "yyyy\-mm\-dd\Thh\:nn\:ss\Z")

End Function ' ISO8601Date

3Lars Berntrop-Bos  03.10.2021 13:24:02  ISO 8601 date format in Lotus Script

I added the slashes before the minus , T, Z and colon characters to prevent localization interfering. Plus it is now only one function call

4Karl Hartmann  04.10.2021 17:21:59  ISO 8601 date format in Lotus Script

What about

ISO8601Date = Format$(dateTime.LSGMTTime, "YYYY-MM-DD hh:mm:ss")

5Lars Berntrop-Bos  06.10.2021 21:40:29  ISO 8601 date format in Lotus Script

@Karl

The colons are translated to the time separator for you region. Which may not be the colon needed for ISO 8601. That is why I use the escape characters, to force the characters I want in the string. And your spec is missing the T and Z characters.

See: https://en.wikipedia.org/wiki/ISO_8601

30 years of having to dot my i's and cross my t's finally paying off...

Links

    Archives


    • [IBM Lotus Domino]
    • [Domino on Linux]
    • [Nash!Com]
    • [Daniel Nashed]