Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
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 (3)
1 Solution

Accepted Solutions
sunny_talwar

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

Now() function won't work.. can you tell me what is the purpose to use now() here?
Please add me Anil_Babu_Samineni to interact faster when reply back. Speak low think High.

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
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

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;
tresesco
MVP
MVP

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 @tresesco.

Same timezone, yes.

sunny_talwar

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

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