Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
morenoju
Partner - Specialist
Partner - Specialist

Field not updating after automatic load

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

Labels (2)
1 Solution

Accepted Solutions
sunny_talwar
MVP
MVP

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

image.png

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.

View solution in original post

17 Replies
Anil_Babu_Samineni
MVP
MVP

Now() function won't work.. can you tell me what is the purpose to use now() here?
Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
morenoju
Partner - Specialist
Partner - Specialist
Author

I used Now() because I wanted to check the current time.
E.g If it’s 19:45 now, the CurrentPeriod must be 0 because it’s later than 19:00.
Do you have any alternative function I can use?
sunny_talwar
MVP
MVP

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;
tresB
Champion III
Champion III

Is your server in the same timezone as you are?
morenoju
Partner - Specialist
Partner - Specialist
Author

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

morenoju
Partner - Specialist
Partner - Specialist
Author

Hi @tresB.

Same timezone, yes.

sunny_talwar
MVP
MVP

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 

morenoju
Partner - Specialist
Partner - Specialist
Author

12/5/2018 8:50:20 AM. The value I had expected.
I'm thinking of going back to use a variable. Something like
SET CurrentPeriod = If(Now() >= MakeTime(6) and Now() < MakeTime(10), 1, If(Now() >= MakeTime(16) and Now() < MakeTime(19), 2, 0))
sunny_talwar
MVP
MVP

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()