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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

get Year from date variable

Hi,

I have the following code:

Temp:

Load Max(OrderDate) as MaxOrderDate Resident ORDER_2_CUST_SHIPPER;

Let currDate=Date(FieldValue('MaxOrderDate',1),'DD-MMM-YYYY');

Let currYear=Year($(currDate));

Drop Table Temp;

When I debug currYear is <NULL>.
I have also tried Let currYear=Year('$(currDate)'); but I get the same result.
If I try something like Let currYear=Year(Date(FieldValue('MaxOrderDate',1),'DD-MMM-YYYY'));

then I get the correct value, but this solution is not very dry.

Cheers

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

I figured it out

Way that it worked is:

Let currYear=Year(currDate);

But, I still do not understand completely how usage of $ works in QlikView, and it is strange, to say the least
In this case, $ did not work for Year function. In same script I had


Let prevYearDate = MakeDate(Year(Date(FieldValue('MaxOrderDate',1),'DD-MMM-YYYY'))

      - 1,$(currMonth),$(currDay));

and it was working correctly. So, in Year function $ did not work and in MakeDate it did work...

My assumption was that no $ is used in script, and $ is used when calling script variables in expressions, but this MakeDate function working properly and Year not, is confusing.
So, if anyone has any idea why is it so please share

View solution in original post

3 Replies
Anonymous
Not applicable
Author

I figured it out

Way that it worked is:

Let currYear=Year(currDate);

But, I still do not understand completely how usage of $ works in QlikView, and it is strange, to say the least
In this case, $ did not work for Year function. In same script I had


Let prevYearDate = MakeDate(Year(Date(FieldValue('MaxOrderDate',1),'DD-MMM-YYYY'))

      - 1,$(currMonth),$(currDay));

and it was working correctly. So, in Year function $ did not work and in MakeDate it did work...

My assumption was that no $ is used in script, and $ is used when calling script variables in expressions, but this MakeDate function working properly and Year not, is confusing.
So, if anyone has any idea why is it so please share

sasiparupudi1
Master III
Master III

pl close this thread by marking a correct answer

Anonymous
Not applicable
Author

If I mark it as answered then no one will bother to explain to me passing of variables to Year and MakeDate and why $ works in one and not another function.
I will wait for few days and then mark it as answered if no one bothers to answer.