GetTime and GetDate will return local format of date/time. When dealing with databases it's the ISO 8601 format that is used. I would like to have a GetIsoTimestamp command for this. UTC is always used except in format=2 where the offset is part of the output.
Example output(s):
Format=1 standard
2023‐09‐14T05:11:00Z
Format=2 UTC offset
2023‐09‐13T22:11:00−07:00 UTC−07:00
2023‐09‐14T05:11:00+00:00 UTC+00:00
2023‐09‐14T12:11:00+07:00 UTC+07:00
Format=3 week
2023‐W37
Format=4 week+day
2023‐W37‐4
Format=5 ordinal date
2023‐257
Format=6 date
2023‐09‐14
Format=7 time
05:11:00Z
Format=8 time without special characters
T051100Z
Format=9 timestamp without special characters
20230914T051100Z
ISO 8601 timestamp
Moderators: Dorian (MJT support), JRL
- Grovkillen
- Automation Wizard
- Posts: 1059
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
- Dorian (MJT support)
- Automation Wizard
- Posts: 1369
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: ISO 8601 timestamp
Thank you for this. I will make sure to pass it on.
Yes, we have a Custom Scripting Service. Message me or go here
- Grovkillen
- Automation Wizard
- Posts: 1059
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: ISO 8601 timestamp
For reference, if done in Python:
Code: Select all
//format=1
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")),ISO_8601_format_1
//format=2
PYExec>import datetime%CRLF%print(datetime.datetime.now().astimezone().replace(microsecond=0).isoformat()),ISO_8601_format_2
//format=3
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("%Y-W%V")),ISO_8601_format_3
//format=4
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("%Y-W%V-%u")),ISO_8601_format_4
//format=5
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("%Y-%j")),ISO_8601_format_5
//format=6
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("%Y-%m-%d")),ISO_8601_format_6
//format=7
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("T%H:%M:%SZ")),ISO_8601_format_7
//format=8
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("T%H%M%SZ")),ISO_8601_format_8
//format=9
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("%Y%m%dT%H%M%SZ")),ISO_8601_format_9
//bonus formats
//epoch time
PYExec>import time%CRLF%print(int(time.time())),epoch
//epoch time as float
PYExec>import time%CRLF%print(time.time()),epoch_float
//epoch in nanoseconds
PYExec>import time%CRLF%print(time.time_ns()),epoch_ns
**BREAKPOINT**
- Grovkillen
- Automation Wizard
- Posts: 1059
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: ISO 8601 timestamp
I found out that SQL uses a variant of the ISO format:
2023-09-14T13:18:54.357107+02:00
2023-09-14T13:18:54.357107+02:00
Code: Select all
//format=10
PYExec>import datetime%CRLF%print(datetime.datetime.now().astimezone().isoformat()),ISO_8601_format_10
- Grovkillen
- Automation Wizard
- Posts: 1059
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: ISO 8601 timestamp
Just a clean up to show the output in a message:
Code: Select all
//format=1
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")),ISO_8601_format_1
//format=2
PYExec>import datetime%CRLF%print(datetime.datetime.now().astimezone().replace(microsecond=0).isoformat()),ISO_8601_format_2
//format=3
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("%Y-W%V")),ISO_8601_format_3
//format=4
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("%Y-W%V-%u")),ISO_8601_format_4
//format=5
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("%Y-%j")),ISO_8601_format_5
//format=6
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("%Y-%m-%d")),ISO_8601_format_6
//format=7
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("T%H:%M:%SZ")),ISO_8601_format_7
//format=8
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("T%H%M%SZ")),ISO_8601_format_8
//format=9
PYExec>import datetime%CRLF%print(datetime.datetime.utcnow().strftime("%Y%m%dT%H%M%SZ")),ISO_8601_format_9
//format=10
PYExec>import datetime%CRLF%print(datetime.datetime.now().astimezone().isoformat()),ISO_8601_format_10
//bonus formats
//epoch time
PYExec>import time%CRLF%print(int(time.time())),epoch
//epoch time as float
PYExec>import time%CRLF%print(time.time()),epoch_float
//epoch in nanoseconds
PYExec>import time%CRLF%print(time.time_ns()),epoch_ns
Let>OUTPUT_DATA=OUTPUT:
ConCat>OUTPUT_DATA,%CRLF%%ISO_8601_format_1%
ConCat>OUTPUT_DATA,ISO_8601_format_2
ConCat>OUTPUT_DATA,ISO_8601_format_3
ConCat>OUTPUT_DATA,ISO_8601_format_4
ConCat>OUTPUT_DATA,ISO_8601_format_5
ConCat>OUTPUT_DATA,ISO_8601_format_6
ConCat>OUTPUT_DATA,ISO_8601_format_7
ConCat>OUTPUT_DATA,ISO_8601_format_8
ConCat>OUTPUT_DATA,ISO_8601_format_9
ConCat>OUTPUT_DATA,ISO_8601_format_10
ConCat>OUTPUT_DATA,epoch
ConCat>OUTPUT_DATA,epoch_float
ConCat>OUTPUT_DATA,epoch_ns
MDL>OUTPUT_DATA