Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi guys,
I have the following piece of code in my load script:
[hotspots_currentperiod]: LOAD if (hour(now())>='6' AND hour(now())<'10',1,if (hour(now())>='16' AND hour(now())<'19',2,0)) As CurrentPeriod INLINE [ CurrentPeriod ];
Basically, I want to divide the day in three periods:
- Between 6 and 10 AM it is period 1
- Between 4 PM and 7 PM period 2
- Rest: period 0
This was working OK until I published the app. It is right now 7:25 PM, and I'm reloading data every 5 minutes. CurrentPeriod=2 no matter what.
Do you see anything wrong in my code?
Thanks
I guess what I am trying to understand is the value of Hour(Now()) or Time(Frac(Now())) when the if statement is getting evaluated...
for example... I ran this script
[hotspots_currentperiod]: LOAD Now() as CurrentDateTime, Time(Frac(Now())) as CurrentTime, If(Frac(Now()) >= MakeTime(6) and Frac(Now()) < MakeTime(10), 1, If(Frac(Now()) >= MakeTime(16) and Frac(Now()) < MakeTime(19), 2, 0)) as CurrentPeriod_Time, Hour(Now()) as CurrentHour, If(Hour(Now()) >= 6 and Hour(Now()) < 10, 1, If(Hour(Now()) >= 16 and Hour(Now()) < 19, 2, 0)) as CurrentPeriod_Hour AutoGenerate 1;
and I am seeing this
I am seeing that CurrentTime is 9:31:40 AM and Current Hour is 9... so it make sense that I am getting 1... what do you get when you run the above script? Share a screenshot similar to what I posted using the above script.
Try this
[hotspots_currentperiod]: LOAD If(Now() >= MakeTime(6) and Now() < MakeTime(10), 1, If(Now() >= MakeTime(16) and Now() < MakeTime(19), 2, 0)) as CurrentPeriod AutoGenerate 1;
Hi @sunny_talwar,
I tried that and the result was strange. CurrentPeriod=2 even though it's 8:36 AM right now.
Any other alternative?
Thanks
Hi @tresesco.
Same timezone, yes.
Try running this
[hotspots_currentperiod]: LOAD Now() as CurrentDateTime, If(Now() >= MakeTime(6) and Now() < MakeTime(10), 1, If(Now() >= MakeTime(16) and Now() < MakeTime(19), 2, 0)) as CurrentPeriod AutoGenerate 1;
and see what value do you see for CurrentDateTime
Now can you try this
[hotspots_currentperiod]: LOAD Now() as CurrentDateTime, Time(Frac(Now())) as CurrentTime, If(Frac(Now()) >= MakeTime(6) and Frac(Now()) < MakeTime(10), 1, If(Frac(Now()) >= MakeTime(16) and Frac(Now()) < MakeTime(19), 2, 0)) as CurrentPeriod AutoGenerate 1;
Changed the if statement to use Frac(Now()) instead of Now()