Page 1 of 1

Current date and Date user variables

Posted: Monday 10 December 2018 22:41
by galinette
Hi,

I want to do a simple thing : test if the current date matches the value of a user variable of "Date" type.

Code: Select all

domoticz.variables("MyDate").value
returns a string that looks like : "25/12/2018"

but:

Code: Select all

domoticz.time.rawDate
returns a string that looks like : "2018-12-25"

So I cannot compare the two. Also:

Code: Select all

domoticz.time.matchesRule('on '.. domoticz.variables("MyDate").value)
Does not work since the trigger rules cannot have a dd/mm/yyyy format, only dd/mm

As a workaround I now rely on:

Code: Select all

local day = domoticz.time.day
local month = domoticz.time.month
local year = domoticz.time.year
local date = day .. '/' .. month .. '/' .. year
if date==domoticz.variables(MyDate').value then
That's quite cumbersome for a simple task, and this is awfully non robust as it will break if the date format changes.

Is there any good solution?

Thanks!

Re: Current date and Date user variables

Posted: Tuesday 11 December 2018 0:50
by waaren
galinette wrote: Monday 10 December 2018 22:41 I want to do a simple thing : test if the current date matches the value of a user variable of "Date" type.

Code: Select all

domoticz.variables("MyDate").value
returns a string that looks like : "25/12/2018"

Code: Select all

domoticz.time.rawDate
returns a string that looks like : "2018-12-25"
Is there any good solution?
yes !
use

Code: Select all

domoticz.time.matchesRule('on '.. domoticz.variables("MyDate").date.rawDate)
Other Variable attributes and methods can be found here

Re: Current date and Date user variables

Posted: Tuesday 11 December 2018 6:44
by dannybloe
Or you use the date object’s compare function. See the docs.