How to compare 2 date strings which is earlier

For my wastebin I receive the next date of emptying. I want to compare dates like:

condition: "{{ states(‘sensor.twente_milieu_organic_waste_pickup’) < states(‘sensor.twente_milieu_packages_waste_pickup’) }} "

This seems not to work…States(‘sensor.twente_milieu_organic_waste_pickup’) return values like “2023-10-29”.

Convert each date string to a datetime object using as_datetime.

{{ states('sensor.twente_milieu_organic_waste_pickup') | as_datetime < states('sensor.twente_milieu_packages_waste_pickup') | as_datetime }}