From 8cfc596b17291e5be8363409c455f838eda37f78 Mon Sep 17 00:00:00 2001 From: Martijn van der Pol Date: Mon, 29 Jan 2024 18:51:50 +0100 Subject: [PATCH] Add `default` parameter to `as_datetime` documentation (#31048) --- source/_docs/configuration/templating.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/_docs/configuration/templating.markdown b/source/_docs/configuration/templating.markdown index 131d083e9a6..33f07722ad2 100644 --- a/source/_docs/configuration/templating.markdown +++ b/source/_docs/configuration/templating.markdown @@ -587,7 +587,7 @@ For example, if you wanted to select a field from `trigger` in an automation bas {% endraw %} -- `as_datetime()` converts a string containing a timestamp, or valid UNIX timestamp, to a datetime object. +- `as_datetime(value, default)` converts a string containing a timestamp, or valid UNIX timestamp, to a datetime object. If that fails, returns the `default` value, or if omitted raises an error. This function can also be used as a filter. - `as_timestamp(value, default)` converts datetime object or string to UNIX timestamp. If that fails, returns the `default` value, or if omitted raises an error. This function can also be used as a filter. - `as_local()` converts datetime object to local time. This function can also be used as a filter. - `strptime(string, format, default)` parses a string based on a [format](https://docs.python.org/3.10/library/datetime.html#strftime-and-strptime-behavior) and returns a datetime object. If that fails, it returns the `default` value or, if omitted, raises an error.