Convert string to be able to compare 2 dates

Hi,

I’m scraping a string from a website, which displays as ‘September 19, 2022’. I have been trying everything to convert it to a date so I can compare it to my ‘sensor.date’, which is formatted as ‘19-09-2022’. How can I do this?

Thank you!

{{ strptime('September 19, 2022', '%B %d, %Y').date() }}

Thank you, that works.But, I should have clarified… the website displays a date in the format I posted above. I scraped that and created a sensor with that data. I would like to change the sensor from that date as a string into the date in home assistant. So something like this I thought would work, based off of what you wrote.

{{ strptime('states.sensor.name_of_sensor.state', '%B %d, %Y').date() }}

Yes that would work if you did not quote the sensor.

Or better:

{{ strptime(states('sensor.name_of_sensor'), '%B %d, %Y').date() }}
1 Like

This was it, thank you!!!