cancel
Showing results for 
Search instead for 
Did you mean: 

Based on todays date check the last months last date

former_member190358
Participant
0 Kudos

Hello SAP Gurus,

I have to find the last date  of the last month based on today's date

Can someone help me that how can i achieve that either with UDF or with some other method.

Regards,

Ravi

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member184720
Active Contributor
0 Kudos

Can you try with below UDF?

Calendar cal = Calendar.getInstance();

cal.add(Calendar.MONTH, -1);

cal.set(Calendar.DATE, 1);

cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));

Date lastDateOfPreviousMonth = cal.getTime();

DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

String lastDate = df.format(lastDateOfPreviousMonth);

return lastDate;

reference : datetime - How to get the first date and last date of the previous month? (Java) - Stack Overflow