1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Correct method to get timedelta seconds value (#37485)

* Correct method to get timedelta seconds value

This also adds additional clarification for extracting different time/date values for time deltas

* Small edit
This commit is contained in:
Owen Kuemerle 2018-03-20 15:00:34 -04:00 committed by scottb
parent 775539a8b8
commit ba4f26313b

View file

@ -919,9 +919,15 @@ This will result in::
To get date object from string use the `to_datetime` filter, (new in version in 2.2):: To get date object from string use the `to_datetime` filter, (new in version in 2.2)::
# get amount of seconds between two dates, default date format is %Y-%m-%d %H:%M:%S but you can pass your own one # Get total amount of seconds between two dates. Default date format is %Y-%m-%d %H:%M:%S but you can pass your own format
{{ (("2016-08-14 20:00:12"|to_datetime) - ("2015-12-25"|to_datetime('%Y-%m-%d'))).seconds }} {{ (("2016-08-14 20:00:12"|to_datetime) - ("2015-12-25"|to_datetime('%Y-%m-%d'))).total_seconds() }}
# Get remaining seconds after delta has been calculated. NOTE: This does NOT convert years, days, hours, etc to seconds. For that, use total_seconds()
{{ (("2016-08-14 20:00:12"|to_datetime) - ("2016-08-14 18:00:00"|to_datetime)).seconds }}
# This expression evaluates to "12" and not "132". Delta is 2 hours, 12 seconds
# get amount of days between two dates. This returns only number of days and discards remaining hours, minutes, and seconds
{{ (("2016-08-14 20:00:12"|to_datetime) - ("2015-12-25"|to_datetime('%Y-%m-%d'))).days }}
Combination Filters Combination Filters
```````````````````` ````````````````````