Date and time template functions
These template functions help you work with dates, times, and durations. Use them to get the current time, format timestamps for display, calculate how long ago something happened, or convert between different time representations.
Home Assistant extends the Jinja2 template engine with many custom functions, filters, and tests. Each function on this page has its own page with detailed descriptions, parameters, and practical examples.
New to templates? Start with the templating documentation to learn the basics.
-
Convert to datetime
as_datetimeConverts a string or timestamp to a datetime object. -
Convert to local time zone
as_localConverts a datetime object to your local time zone. -
Parse duration string
as_timedeltaParses an ISO 8601 duration string into a timedelta object. -
Convert to UNIX timestamp
as_timestampConverts a datetime object or string to a UNIX timestamp. -
Current local date and time
nowReturns the current date and time in your local time zone. -
Relative time (deprecated)
relative_timeReturns a human-readable string describing how long ago a datetime was. -
Parse a time string
strptimeParses a time string with a specified format into a datetime object. -
Human-readable time elapsed
time_sinceReturns a human-readable string describing how much time has passed since a datetime. -
Human-readable time remaining
time_untilReturns a human-readable string describing how much time remains until a datetime. -
Create a time duration
timedeltaCreates a timedelta object from numeric time components. -
Format timestamp with custom format
timestamp_customFormats a UNIX timestamp as a string using a custom format. -
Format timestamp as local time
timestamp_localFormats a UNIX timestamp as a local datetime string. -
Format timestamp as UTC time
timestamp_utcFormats a UNIX timestamp as a UTC datetime string. -
Today at a specific time
today_atReturns today's date combined with a specific time. -
Current UTC date and time
utcnowReturns the current date and time in UTC.