Forum Discussion
DougHenning1
2 years agoCommunity Manager
You can use strftime to specify the formatting. This should do the trick:
%F date formatted as "YYYY-MM-DD"
T Literal character
%T time in 24 hour format
[:-3] strips the last three characters from the end
~ "Z" appends the letter Z to the end
------------------------------
Doug Henning
------------------------------
{{ time.now.strftime("%FT%T.%f")[:-3] ~ "Z" }}​
%F date formatted as "YYYY-MM-DD"
T Literal character
%T time in 24 hour format
[:-3] strips the last three characters from the end
~ "Z" appends the letter Z to the end
------------------------------
Doug Henning
------------------------------
- JeremyLahners2 years agoQrew CadetHey Doug, this definitely got me closer, especially for DateTime fields. Now I am just struggling with separate Date and Time fields. Any suggestions on how to combine a Date and Time field into one datetime object so I can apply strftime() to it?
Date: 2023-01-17
Time: 4:00 PM
Desired Output: 2023-01-17T16:00:00Z
------------------------------
Jeremy Lahners
LeadBaller
------------------------------- DougHenning12 years agoCommunity ManagerCombine the date and time with space separator, then use time.parse to parse the combined string into a datetime value:
{% set reportDate = "2023-01-16" %} {% set reportTime = "4:37 pm" %} {% set reportStart = time.parse(reportDate ~ " " ~ reportTime) %} {{ reportStart.strftime("%FT%T.%f")[:-3] ~ "Z" }}
------------------------------
Doug Henning
------------------------------- PrashantMaheshw2 years agoQrew Captain@Doug Henning
[:-3] is a neat example of right slicing. Thank You .
------------------------------
Prashant Maheshwari
------------------------------