cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for last day of week/month

Former Member
0 Kudos

Input is a Date(For example: 2010/03/12) in String format.

I need to extract the last day of that week and return it as a string output.

For example if input is 2010/03/12 and thatu2019s a Thursday my output should be 2010/03/14 i.e Saturdayu2019s date.

Similarly I need to extract last day of month too.

Thanks in advance

Soumen...

Accepted Solutions (1)

Accepted Solutions (1)

former_member181962
Active Contributor
0 Kudos

Modify this code in your UDF:

http://www.kodejava.org/examples/134.html

Regards,

ravi

stefan_grube
Active Contributor
0 Kudos

I think i had the same source when I needed that function

Here the last day in a month:

String yearS = var1.substring(1,5);
int year =  Integer.parseInt(yearS);
// get month (note: January = 0)
String monthS = var1.substring(6,8);
int month = Integer.parseInt(monthS) - 1;
// determine last day of month
Calendar calendar = Calendar.getInstance(); 
calendar.set(year,month,1);
int lastDate = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); 
String lastDateS = Integer.toString(lastDate);

String dateS = yearS + monthS + lastDateS;
return dateS;

Former Member
0 Kudos

Thanks Stefan,Sarvesh & Ravi...You guys Rock!!!

EDIT : For last day of week ???

Edited by: SoumenDas2009 on May 12, 2010 3:31 PM

Former Member
0 Kudos

hi Soumen,

see this code : [http://www.kodejava.org/examples/134.html|http://www.kodejava.org/examples/134.html]

or this one:

[http://www.roseindia.net/java/java-get-example/get-last-day-month.shtml|http://www.roseindia.net/java/java-get-example/get-last-day-month.shtml]

that helped me.

Regards.

Mickael

Former Member
0 Kudos

@Mickael Huchet : I need the logic for Last day of week now.

Former Member
0 Kudos

Hi,

I did not develop this one... but just use "search" button on roseindia and you will have the answer (I think):

[http://www.roseindia.net/java/beginners/DayOfYearToDayOfWeek.shtml|http://www.roseindia.net/java/beginners/DayOfYearToDayOfWeek.shtml]

and do not forget that Google is your friend...

do a research with : Java last day of week, and you have plenty of examples.

)

Thanks.

P.S: Say us when you will solved your problem.

Answers (1)

Answers (1)

Former Member
0 Kudos

You can also try this...

Under Imports java.util.Date;

Calendar cal = Calendar.getInstance(); 
	
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));

String lastday = "" + cal.getTime();

String dlvday = lastday.substring(0,3);
String dlvdate = lastday.substring(8,10);


String dateofdelivery = dlvdate + lastday.substring(4,7) + lastday.substring(24,28);
return dateofdelivery;