Discussions

 View Only
  • 1.  Jinja ISO Date format in Pipeline

    Posted 16 days ago
    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
    ------------------------------


  • 2.  RE: Jinja ISO Date format in Pipeline

    Posted 15 days ago
    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
    ------------------------------



  • 3.  RE: Jinja ISO Date format in Pipeline

    Posted 15 days ago
    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
    ------------------------------



  • 4.  RE: Jinja ISO Date format in Pipeline

    Posted 15 days ago
    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
    ------------------------------



  • 5.  RE: Jinja ISO Date format in Pipeline

    Posted 14 days ago
    @Doug Henning

    [:-3] is a neat example of right slicing. Thank You .

    ------------------------------
    Prashant Maheshwari
    ------------------------------



  • 6.  RE: Jinja ISO Date format in Pipeline

    Posted 14 days ago
    Beautiful solution!  Thank you so much!

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