Current Time and Date/Time Arithmetic¶
Current Time¶
To put current date-time in a field you need the following template:
{{time.now}}
You can also get the time at the beginning of the date Today (00:00:00) with: time today
{{time.today}}
Time Arithmetic¶
Sometimes you need to get a date in the future or in the past. Usually this will be a due date or similar. To do that
you can use the time.now
and time.today
together with time.delta
. time.delta
is a time offset object
which you can add or subtract from a datetime to get a datetime in the future or the past.
Relative Time Delta¶
time.delta
can be used with relative arguments to get relative time offset. The available arguments
are years, months, weeks, days, hours, minutes, seconds. Note that all of them a plural, as opposed to
singular year, month, etc., which are used for absolute time delta (replacement of current value).
For example to get the same time one hour from now you can use:
{{time.now + time.delta(hours=1)}}
Similarly to get a time at the beginning of day one week from now you can do:
{{time.today + time.delta(days=7)}}
Note that months and years takes into account the current date, so time.now + time.delta(months=1)
actually
results in the same date one month from now, unless next month has less days than the current day of the month in which
case it results in last day of next month. For example if today is 2016-01-27 and we add time.delta(months=1) the end
result is 2016-02-27, but if today is 2016-01-31, since February 2016 has 29 days the result will be 2016-02-29.
Absolute Time Delta¶
Similar to relative delta above, you can give the following arguments to time.delta
to get an absolute offset, that
is replace the current value with the one from the delta: year, month, day, hour, minute, and second.
For example to get same datetime as now in 2012 you can do:
{{time.now + time.delta(year=2012)}}
Timezone Filter¶
All datetimes which flow through Cloudpipes are in UTC. In general you don’t need to do any timezone
conversion yourself if you map between datetime fields, even between different channels. Sometimes however you may
want to print the time in a text field in a user-friendly timezone. You can do that with the timezone
filter.
{{time.now|timezone}}
{{time.now|timezone('UTC')}}
{{time.now|timezone('EST')}}
{{time.now|timezone('Australia/Darwin')}}
renders to:
2016-07-28 13:18:26.889542+00:00
2016-07-28 13:18:26.889571+00:00
2016-07-28 08:18:26.889584-05:00
2016-07-28 22:48:26.889603+09:30
The default timezone is UTC, so {{time.now|timezone}}
is equivalent to {{time.now|timezone('UTC')}}
. You can
find your timezone’s name in the TZ column in this
Wikipedia Article.
Date Format Filters¶
Warning: do not use this filter to transfer dates between date-typed fields. We handle the remote system date format. This filter is intended for formatting dates into string-typed (human-readable) fields.
Date are usually formatted as timestamp for inside Cloudpipes. Sometimes you might need to format the date in another
format or display just the date options. You can use these filters to do that: date_ymd
, date_dmy
, and
date_mdy
.
{{time.now|date_ymd}}
{{time.now|date_mdy}}
{{time.now|date_dmy}}
renders to:
2016-09-20
09-20-2016
20-09-2016
Note that there is an optional separator argument to the filter. The default separator is -
.
{{time.now|date_ymd('')}}
{{time.now|date_mdy('/')}}
{{time.now|date_dmy('.')}}
renders to:
20160920
09/20/2016
20.09.2016
Note that when separator is not given -
is used and that you can specify empty string with two single quotes ''
.