hi,
I struggle with datetime items and their way of formating it. I need to compare today with an datetime item. I don’t care about the time, only date is important.
how to convert the item to match the format of “now.toLocalDate”.
rule "Check if DateTime Item is today"
when
Item vSwitch1 changed
then
// Get the current date
val currentDate1 = now
val currentDate2 = now.toLocalDate
// Get the DateTime Item value
val itemDate1 = (BirthdayDate.state as DateTimeType).getZonedDateTime()
val itemDate2 = BirthdayDate.state
//val itemDate2 = BirthdayDate.valueOf(now.toLocalDateTime().toString())
//val itemDate3 = BirthdayDate.getZonedDateTime.toLocalDate
// Check if the DateTime Item is set to today
if (currentDate1 == itemDate1) {
// Do something because the DateTime Item is set to today
// For example, trigger another Item or execute some actions
logInfo("testrule2", "success")
}
logInfo("testrule2", "currentdate1: " + currentDate1 + " currentdate2: " + currentDate2 + ", itemdate1: " + itemDate1 + " itemdate2: " + itemDate2 )
end
2023-12-27 12:11:38.243 [INFO ] [.openhab.core.model.script.testrule2] - currentdate1: 2023-12-27T12:11:38.242701233+01:00[Europe/Berlin]currentdate2: 2023-12-27, itemdate1: 2023-12-27T00:00+01:00 itemdate2: 2023-12-27T00:00:00.000+0100