
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Date format
how to achieve date format as
let vcurrentyear = year(Today());
let vr = '07/01/(vcurrentyear)' ;
where we want to make vcurrentyear dynamic .
- « Previous Replies
-
- 1
- 2
- Next Replies »
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @ritumishra01 ,
The concept of the code is that you need an initial declaration of the entity storing the dates, and then a mechanism to update the dates yearly. If you already have initial declaration, then yes you can load the old file and then store the changed data into a new file.
In summary,
- You need to schedule the app to run yearly (or at your preferred time interval)
- The app will load the old file, check the same if condition of Now() >= vend (If you know all data will change to certain date at the time of scheduled load, then maybe there is no need for the if condition).
- Store table into the new path. (You can store to a new file name or/and folder name)
vYear = Year(Today()); vYY = Right('$(vYear)', 2); STORE enc4 INTO [lib://authenticateddata\wbhi_$(vYear)\Enc_fy_$(vYY).qvd](qvd);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I understand your question correctly, then by using makedate() function.
Let vr = makedate($(vcurrentyear), 07, 01);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did it work for you @ritumishra01 ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
let vr = Date#('07/01/' & vcurrentyear, 'MM/DD/YYYY'); // Use Date# to format the date

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to compare two dates
if(date($(vcurrentdate)) >= date($(vStartCheck))) then
let vStart1 = date#('07/01/$(vcurrentyear)','MM/DD/YYYY') else
here else statement is not working

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Code below works fine with me. But this is the control statements IF (Outside the LOAD). Qlik Help
let vStartCheck = '6/1/2023';
let vcurrentyear = year(Today());
let vcurrentdate = '07/01/$(vcurrentyear)'; //MakeDate($(vcurrentyear), 07, 01)
Trace vcurrentyear: $(vcurrentyear);
Trace vcurrentdate: $(vcurrentdate);
If date($(vcurrentdate)) >= date($(vStartCheck)) THEN
let vStart1 = date#('07/01/$(vcurrentyear)','MM/DD/YYYY');
ELSE
let vStart1 = 'Tomato';
END IF
Trace vStart1: $(vStart1);
Now if you want the if statement to be inside the LOAD (Qlik Help), this is the syntax:
If(A = B, <Do if True>, <Do if False>)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey Hesham, thanks for your response.
i am using the below query .and i could not achieve what is needed.
IF-ELSE is not working as expected.
what we are looking for is this that vstart should be '7/1/2023 00:00' and vENd should be '6/30/2024 23:5923:59';
and as soon as '6/30/2024 23:5923:59'; date reaches .Vstart should become 7/1/2024 00:00' and Vend should be '6/30/2025 23:5923:59';.
Any help will be much apriciated .
let vcurrentyear = year(Today());
let vcurrentyear_1 = (year(today())+1);
let vcurrentyear_2 = (year(today())+2);
let vcurrentdate = date(today(),'MM/DD/YYYY');
let vStartC = num(date#(MakeDate($(vcurrentyear), 07,01),'MM/DD/YYYY'));
let vEndC =num(date(MakeDate($(vcurrentyear_1),06, 30),'MM/DD/YYYY'));
IF(NUM($(vcurrentdate)) > NUM($(vStartC)))
THEN
let vStart = date#('07/01/$(vcurrentyear)','MM/DD/YYYY') ;
let vEnd = date#('06/30/$(vcurrentyear_1)','MM/DD/YYYY');
ELSE
let vStart = date#('07/01/$(vcurrentyear_1)','MM/DD/YYYY');
let vEnd = date#('06/30/$(vcurrentyear_2)','MM/DD/YYYY');
END IF
;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @ritumishra01 ,
Your scenario is a bit tricky, as it needs initial declaration, and then continue with the logic.
Code below sets the variable of their initial value and then checks the condition. After running the script for the first time, the variables are defined and saved in the app. Then, you have to comment the first two lines so the variables are not overwritten with the initial values again.
// Two variables below are to be commented after first load.
Let vstart = '2020-07-01 00:00:00.000';
Let vENd = '2021-06-30 00:00:00.000';
// Let vNow = Now();
Let vNow = '2021-08-05 14:57:24.000'; //Defining my own Now just to test code
If vNow >= vENd THEN
LET vstart = AddYears('$(vstart)', 1);
LET vENd = AddYears('$(vENd)', 1);
END IF
Trace vstart: $(vstart);
Trace vENd: $(vENd);
Check it and let me know if it works.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
how will this set vStart and Vend every year ?dynamic loading ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did you try to run the code and change the vNow value? If you do so you will see that vStart and Vend are changing dynamically.
When you want to deploy the app, make variable vNow = Now() and schedule the task in QMC as per your preference.

- « Previous Replies
-
- 1
- 2
- Next Replies »