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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Issue in Current Year And Month Retrieval From Current Date

Hi ,

       I am trying to retreive current Year and month using below code in qlikview:

LET vCurrentDate = today();

// Current Year

LET vCurrentYear =Year($(vCurrentDate));

// Current Month

LET vCurrentMonth =($(vCurrentDate));

Always vCurrentYear is populted with 1990 and vCurrentMonth  is populated with  May.. But I never see correct data has been assigned to these Qlikview variables.

Any thoughts?.

Here are the settings I have :

SET TimeFormat='h:mm:ss TT';

SET DateFormat='YYYY-MM-DD';

SET TimestampFormat='YYYY-MM-DD hh:mm:ss';

SET MonthNames='Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec'

Thanks

Dasu.G

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Thanks for the explanation of the low dates Jonathan. I've often wondered about that.

Jonathan

View solution in original post

3 Replies
Anonymous
Not applicable
Author

Try:

LET vCurrentDate = today();

LET vCurrentYear = '=Year(vCurrentDate)';

LET vCurrentMonth = '=Month(vCurrentDate)';

Double quotes are a problem, and the dollar expansion doesn't seem to be necessary.

Jonathan

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

Your first Let statement sets vCurrentDate to '2013-01-21' (or whatever is the correct value for Today(). The second Let "evaluates" the expression 2013 - 1 - 21 = 1991 and uses 1991 as the day number (which corrreponds to the date 1905/06/13.

You do not need $ expansions here, but if you use them, enclose in single quotes so that instead of evaluating an expression, QV is expanding a string:

LET vCurrentYear =Year('$(vCurrentDate)');

LET vCurrentMonth =Month('$(vCurrentDate)');

But even simpler:

LET vCurrentYear =Year(vCurrentDate);

LET vCurrentMonth =Month(vCurrentDate);

Hope that helps

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Anonymous
Not applicable
Author

Thanks for the explanation of the low dates Jonathan. I've often wondered about that.

Jonathan