How can I compare an empty/uninitialized datetime variable?


#1

1) Give a description of the problem
My piston defines a datetime variable called LastNotice and does not assign it a value. In the local variables list, it displays that this variable is “Invalid Date” in light grey text. It’s not null or blank.

2) What is the expected behaviour?
I want to compare $now to this variable to prevent my piston from running too often. I need some way of initializing it once, because then it will retain the value and run properly.

3) What is happening/not happening?
I’ve tried a few ways of doing this, comparing the integer of $now and my variable which hasn’t been set. The log tells me that it compared two integers, which baffles me because how is the value for my LastNotice variable derived?

I can’t seem to compare it to null or a blank value either, since it always comes up with some integer value during these comparisons. So I haven’t been able to check if the variable doesn’t have a value, since it somehow does when the piston is run.

**4) Post a Green Snapshot of the piston![image|45x37]

5) Attach logs after turning logging level to Full

|+132ms|║║Calculating (integer) 1474806400 - (integer) 1474806391 >> (integer) 9|
|---|---|
|+135ms|║║Comparison (integer) 9 is_less_than (integer) 30000 = true (1ms)|
|+136ms|║║Condition #41 evaluated true (10ms)|
|+137ms|║║Condition group #38 evaluated true (state did not change) (12ms)|
|+139ms|║║Cancelling statement #39's schedules...|

#2

Just initialize by clicking on the pencil while not in edit mode and changing to value. It will default to the current time.

59%20AM


#3

I was hoping to avoid that so I could share my piston with people and not have to tell them to set the variable in order for it to work.

However, I was helped in the facebook group to find the answer to my problem in this thread. apparently an unset datetime variable will default to = $now when a piston runs, which was my problem. fortunately, since i’m just comparing the integer values anyway, i simply changed my variable type to integer. since it defaults to 0 when unset, it allows my piston to run normally the first time. Worked perfectly.


#4

Other option is to add a simple block. This will initialize the variable when you press the ‘Test’ button.

if $currentEventttribute is test
then
   set LastNotice=$now
end if

#5

Not tested with datetime, but I sometimes cheat and use a second (empty) variable to achieve this:

pic