Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
HPW
Contributor II
Contributor II

Date as variable

Hello,

I'm setting in a script todays date as variable by using vLastRun=today(). In the list of variables the definition of the variable shows 14.02.2022, but .2022 of the definition is underlined in red. In the further script the usage of that variable leads to a syntax error. Already setting a new variable with the value of the first one by using vLastRun2=$(vLastRun) leads to the syntax error. Using the variable in a WHERE-clause is also not working.

It seems that the variable is not identified as date.

How I have to handle a variable to be used as date?

I guess there is as always an easy solution that I have not in mind as new user of QlikView.

Best regards

Labels (1)
1 Solution

Accepted Solutions
hic
Former Employee
Former Employee

The statement
   Let vLastRun=today()
will indeed assign a variable the date value. But then you need to use it properly.

The $(...) construction is a macro expansion, which means that if you write
   Let vLastRun2=$(vLastRun);
the parser will see
   Let vLastRun2=14.02.2022;
which is an incorrect syntax.

Try
   Let vLastRun2=$(#vLastRun); // Force numeric value
or
   Let vLastRun2='$(vLastRun)';
or
   Let vLastRun2=vLastRun;
or
   Let vLastRun2=Num(vLastRun);

See more on
https://community.qlik.com/t5/Qlik-Design-Blog/Why-don-t-my-dates-work/ba-p/1465849
https://community.qlik.com/t5/Qlik-Design-Blog/Data-Types-in-QlikView/ba-p/1474977

View solution in original post

2 Replies
hic
Former Employee
Former Employee

The statement
   Let vLastRun=today()
will indeed assign a variable the date value. But then you need to use it properly.

The $(...) construction is a macro expansion, which means that if you write
   Let vLastRun2=$(vLastRun);
the parser will see
   Let vLastRun2=14.02.2022;
which is an incorrect syntax.

Try
   Let vLastRun2=$(#vLastRun); // Force numeric value
or
   Let vLastRun2='$(vLastRun)';
or
   Let vLastRun2=vLastRun;
or
   Let vLastRun2=Num(vLastRun);

See more on
https://community.qlik.com/t5/Qlik-Design-Blog/Why-don-t-my-dates-work/ba-p/1465849
https://community.qlik.com/t5/Qlik-Design-Blog/Data-Types-in-QlikView/ba-p/1474977

HPW
Contributor II
Contributor II
Author

Thanks for the quick reply and good solution.