Forum Discussion

JeremyLahners's avatar
JeremyLahners
Qrew Cadet
2 years ago

Jinja ISO Date format in Pipeline

Hey experts,

I am trying to use the value of a field (Date/Time or Date field) in a Pipeline to be sent to a webhook.  I need to output an ISO date but can't figure out how to convert it to the right format.

Currently I'm getting: 2023-01-16 15:59:19.671000+00:00
I need: 2023-01-16T15:59:19.671Z

Is there a Jinja function or something I can use to make this conversion?



------------------------------
Jeremy Lahners
LeadBaller
------------------------------

5 Replies

  • DougHenning1's avatar
    DougHenning1
    Community Manager
    You can use strftime to specify the formatting. This should do the trick:

    {{ 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
    ------------------------------
    • JeremyLahners's avatar
      JeremyLahners
      Qrew Cadet
      Hey 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
      ------------------------------
      • DougHenning1's avatar
        DougHenning1
        Community Manager
        Combine 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
        ------------------------------