Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
ritumishra01
Contributor III
Contributor III

Date format

how to achieve date format as 

let vcurrentyear = year(Today());

let vr = '07/01/(vcurrentyear)' ;

where we want to make vcurrentyear dynamic .

Labels (2)
1 Solution

Accepted Solutions
HeshamKhja1
Partner - Creator II
Partner - Creator II

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,

  1. You need to schedule the app to run yearly (or at your preferred time interval)
  2. 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).
  3. 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);​

 

View solution in original post

12 Replies
HeshamKhja1
Partner - Creator II
Partner - Creator II

If I understand your question correctly, then by using makedate() function.

https://help.qlik.com/en-US/sense/August2023/Subsystems/Hub/Content/Sense_Hub/Scripting/DateAndTimeF...

Let vr = makedate($(vcurrentyear), 07, 01);

HeshamKhja1
Partner - Creator II
Partner - Creator II

Did it work for you @ritumishra01 ?

Aasir
Creator III
Creator III

let vcurrentyear = Year(Today()); // This variable will hold the current year

let vr = Date#('07/01/' & vcurrentyear, 'MM/DD/YYYY'); // Use Date# to format the date
ritumishra01
Contributor III
Contributor III
Author

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 

HeshamKhja1
Partner - Creator II
Partner - Creator II

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>)
ritumishra01
Contributor III
Contributor III
Author

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
;

HeshamKhja1
Partner - Creator II
Partner - Creator II

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.

ritumishra01
Contributor III
Contributor III
Author

how will this set vStart and Vend every year ?dynamic loading ?

 

HeshamKhja1
Partner - Creator II
Partner - Creator II

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.