Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
smilingjohn
Specialist
Specialist

Date

Hi All ,

Can someone please explain me what does the below script does ?

date(MakeDate(year(AddYears(Today(),-2,num(month(Today()))))),'YYYY-MM-DD');

Left(SalesMonth,4) & Right(salesMonth,2) as yearmonth,     ???

Thanks in advance

1 Solution

Accepted Solutions
Anil_Babu_Samineni

First, This expression won't work because you need 2 parameters of AddYears()/ You can split into different variations

Year(AddYears(Today(), -2)) -- 2015

Num(Month(Today())) -- 8

MakeDate(2015, 😎 -- 2015-8thmonth-Starting date of the month (2015-08-01) Because, My format of date is YYYY-MM-DD

Date() -- Returns as we need

Finally, It creates a date for current month of 2 years back date

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful

View solution in original post

6 Replies
Gysbert_Wassenaar

It is supposed to create a date value that's the start of this month two years ago. But the expression is not correct since the parentheses don't match up. It should be =date(MakeDate(year(AddYears(Today(),-2)),num(month(Today()))),'YYYY-MM-DD');

This also gives the wanted result, but is easier to read: Date(MonthStart(Today(),-24),'YYYY-MM-DD')


talk is cheap, supply exceeds demand
clickertape
Contributor II
Contributor II

Wild stab in the dark....

get todays date, get the year of this date, subtract 2 years from it, get the month of this date,format the whole thing as yyyy-mm-dd and convert it to a date

Anil_Babu_Samineni

First, This expression won't work because you need 2 parameters of AddYears()/ You can split into different variations

Year(AddYears(Today(), -2)) -- 2015

Num(Month(Today())) -- 8

MakeDate(2015, 😎 -- 2015-8thmonth-Starting date of the month (2015-08-01) Because, My format of date is YYYY-MM-DD

Date() -- Returns as we need

Finally, It creates a date for current month of 2 years back date

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
tresesco
MVP
MVP

Do you know all the functions being used in this expression? If yes, knowing also that the expression evaluation would be inside-out (inner function's output would be passed to outer function as parameter) would help you know what it is doing. Else, if you don't understand a specific function, let know or search help.

I believe this way you would learn better.

smilingjohn
Specialist
Specialist
Author

hi Gysbert

thanks for the reply ...i got it can you please tell me how does this work ?

Left(SalesMonth,4) & Right(salesMonth,2) as yearmonth,   

Gysbert_Wassenaar

I'm not going to explain every single function. There's an online help where you can find what Left() and Right() do. Have a look at https://help.qlik.com/qlikview


talk is cheap, supply exceeds demand