Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
rajesh90
Contributor
Contributor

Date Subtraction for Month Start Dates

Hello Everyone,

In my code, whenever I pick source files I need to pick T-1 date files. So when I subtract the month starting date with -1 using the below expression it results to incorrect date value,

Expression :

context.Load_Date=String.valueOf(Integer.parseInt(TalendDate.getDate("YYYYMMDD"))-1);

Example :

Input Date = 20210101

Output Date Value received after subtracting 1 = 20210200

The format of the date is YYYYMMDD.

Can you help with a solution to fix this issue.

Thank you.

Labels (2)
1 Solution

Accepted Solutions
prg
Employee
Employee

Hello @Rajesh L R​ ,

 

Please try using the below logic;

 

Date a=TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd");

System.out.println(TalendDate.formatDate("yyyyMMdd", a));

 

0693p00000BZQp6AAH.png 

Please let us know if it helps. If yes, mark it resolved (Kudos also accepted).

 

Regards,

Vaishnavi

View solution in original post

4 Replies
prg
Employee
Employee

Hello @Rajesh L R​ ,

 

Could you please confirm if you mean "T-1" as the previous day?

Please provide us the expected output, so that we can check accordingly.

 

Regards,

Vaishnavi

rajesh90
Contributor
Contributor
Author

Hi @Vaishnavi Khandelwal​ ,

 

Yes T-1 is previous day.

 

Expression :

context.Load_Date=String.valueOf(Integer.parseInt(TalendDate.getDate("YYYYMMDD"))-1);

 

Current Data :

Input Date : 20210301

Output Date : 20210300

 

Expected Data :

Input Date : 20210301

Output Date : 20210228

prg
Employee
Employee

Hello @Rajesh L R​ ,

 

Please try using the below logic;

 

Date a=TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd");

System.out.println(TalendDate.formatDate("yyyyMMdd", a));

 

0693p00000BZQp6AAH.png 

Please let us know if it helps. If yes, mark it resolved (Kudos also accepted).

 

Regards,

Vaishnavi

rajesh90
Contributor
Contributor
Author

It worked, thank you @Vaishnavi Khandelwal​