Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
QlikWorld, June 24-25, 2020. Free virtual event for DI and DA gurus. Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Not applicable

Problem with simple IF Statement

Hi,

I am new to QlikView and have written a simple script to extract data from spreadsheets. While doing so, I have placed a simple if statement to compare two date variables and then execute a load if the condition is satisfield. For some reason the control is not executing the load even when the condition is satisfied. I am sure I have made a silly mistake, but not sure what it is. Please can any one help?

let xyz = Date(FileTime('Data3.xls'));

let abc = today();

if xyz = abc then

CoverDescription:

Mapping Load

CoverCode,

[Short Description]

FROM

Data3.xls

(biff, embedded labels, table is [Coverage-Data$]);

end if

Tags (1)
1 Solution

Accepted Solutions
Highlighted
Not applicable

Problem with simple IF Statement

Hi,

I guess the Date function is still keeping the time information, and when you call today() you have not the time, only the date. Use the num function to do the comparaison, and trace function to see what happen, then take the floor part of tha date, something like :

let xyz = floor(num(Date(FileTime('your file'))));

trace $(xyz);

let abc = num(today());

trace $(abc);

if xyz = abc then

trace ok;

else

trace not ok;

end if

View solution in original post

5 Replies
Highlighted
Not applicable

Problem with simple IF Statement

Hi Tajdeenk,

Typically date/time functions are tricky in QV as sometimes the date comes out in d/m/y format, other times in UTC format (e.g. 45000).

Look in your variable overview in the front end if all your values come out the way they should. (Variable overview is CTRL+ATL+V). I think the today might be coming out in UTC format, hence you would need a date(today()) to format it in the3 right way.

Double check the values in the variable overview. The rest of your statement looks as it should be.

Highlighted
Not applicable

Problem with simple IF Statement

Hi,

I guess the Date function is still keeping the time information, and when you call today() you have not the time, only the date. Use the num function to do the comparaison, and trace function to see what happen, then take the floor part of tha date, something like :

let xyz = floor(num(Date(FileTime('your file'))));

trace $(xyz);

let abc = num(today());

trace $(abc);

if xyz = abc then

trace ok;

else

trace not ok;

end if

View solution in original post

Highlighted
Not applicable

Problem with simple IF Statement

Hi CheenuJanakiram,

Thanks for your reply. I tried your suggestion and still it doesn't work. I can also see the variables containing exactly the same values n Debug mode.

Cheers,

Taj

Highlighted
Not applicable

Problem with simple IF Statement

Hi Renaud.Charlet,

Thanks for your suggestion. It is now working.

Many Thanks,

Taj.

Highlighted
Not applicable

Problem with simple IF Statement

Your welcome, happy to help you. Just keep in mind that a date is always a number, representing the number of days since 1900, with a decimal part for the time, it's easier to use thus number representation for comparisons rather that the real date format.