Search code examples
jinja2getstream-io

Divide by 6 hours in jinja date format


I have time string which represents a time in ISO8601 format.

The formula to format to a date: {{ time.strftime('%Y-%m-%d') }}

Current output:

time = 2018-01-23T08:11:58.000000

output: 2018-01-23

I want to divide it in 6 hours spans:

time = 2018-01-23T08:11:58.000000

output: 2018-01-23_1 // last "1" represents second span of 6 hours in 24 hours day (6-12)

What I need to add to my formula to achieve this?


Solution

  • Just divided hour by 6.

    {{ time.strftime('%Y-%m-%d') }}_{{ time.strftime('%H')/6 }}
    

    and got results:

    2018-01-23_1 // for hours 6-12
    2018-01-23_2 // for hours 12-18
    

    No idea why couldn't think this simple logic earlier.