Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
its_rajvir
Creator
Creator

Understanding Script Fuction

Hi Experts,

I have a Script 

if Len(Trim('$ (vStartDate)'))=0 then
Let vStartDate = Date(Today());
EndIf

Let vStartDate = Date('1/1/2021');

Can Anyone explain its working ?

Thanks in Advance

Labels (4)
2 Solutions

Accepted Solutions
tresesco
MVP
MVP

First if section checks if the variable has got any value or not, if not then today date would be assigned to the variable. And then again the variable value gets overwritten by '1/1/2021'. This is as good as having only the last line of your code, i.e. - if structure is redundant here. This could have a meaning if you had else section in the if structure.

View solution in original post

tresesco
MVP
MVP

Trim() in such cases used to avoid unwanted spaces, because if you don't have a date in variable and have a space your len() would still return value >0. 

View solution in original post

4 Replies
tresesco
MVP
MVP

First if section checks if the variable has got any value or not, if not then today date would be assigned to the variable. And then again the variable value gets overwritten by '1/1/2021'. This is as good as having only the last line of your code, i.e. - if structure is redundant here. This could have a meaning if you had else section in the if structure.

its_rajvir
Creator
Creator
Author

Thank you @tresesco.

Can you explain use of trim function here

tresesco
MVP
MVP

Trim() in such cases used to avoid unwanted spaces, because if you don't have a date in variable and have a space your len() would still return value >0. 

its_rajvir
Creator
Creator
Author

Thankyou so much @tresesco