Extract only parts of the string

Hi,

I am a bit lost on this one.

I want this information to include just the day, month and year. Excluding the time element of the string.

Any ideas on how to achieve this?

Thanks in advance.

If that is a sensor state and you want to just display the date section, create a template sensor (under Helpers) with a state template of:

{{ (states('ENTITY_ID')|as_datetime).date() }}

where ENTITY_ID will be something like sensor.forecast_date or whatever that entity is.

That turns the datetime string (all states are strings) into a date object, which then gets turned back into a string and stored as the state of the template sensor (docs).

To answer the literal question asked, “extract only parts of the string”, you can use string slicing, so this would also work as a state template:

{{ states('ENTITY_ID')[:10] }}

which says “take up to the tenth character of the string”.

Thank you, works perfectly. Very clear instructions - much appreciated.