Page 1 of 1

Syntax dates in scripts

Posted: Monday 10 February 2025 21:29
by HennyN
Hello,

I hope someone can and will help me.

I have a script I use to calculate my energy costs. That works. But.....
Energy costs change annually, so to compare costs per year, I actually need to add a date line to that.

I see in that script: if (domoticz.time == ‘Between 23:00 and 07:00’), but does that work the same way with a date?
So something like: if (domoticz.date == ‘Between 01-01-2023 and 01-01-2024’) etc....

Is that the right syntax, or does that work differently. It is not yet clear to me from the wiki how to do that.
Ultimately, I want to adjust the rates annually so that I can do clean comparisons over years.

Thanks in advance for answers.
Regards, Henny

Re: Syntax dates in scripts

Posted: Monday 10 February 2025 21:40
by HvdW

Code: Select all

local startDate = '2023-01-01'
local endDate = '2024-01-01'
local currentDate = domoticz.time.rawDate

if currentDate >= startDate and currentDate < endDate then
    print("Date is between 01-01-2023 and 01-01-2024")
else
    print("Date is outside the range")
end

Re: Syntax dates in scripts

Posted: Monday 10 February 2025 21:58
by HennyN
Oké, Thanks (Bedankt! HvdW)

I'll work on it and see if I can get it working.