Webmethod Built in Date Service to get first amp last day of a month

Dear all,

I need a help in using built in date service or a Java Service.

My requirement is that if i give the year & month (yyyy,MM) i should get the String representation of the first day and last day of the month.

For example

if i give 2000 as year (leap year) and 02 as month i should get 1 and 29 since it is a leap year and other that leap year it should be 1 and 28.

if i give 2000 and month as 03 i should get 1 and 31st as first and last day.

Is there any build in flow service available / or customised java service code.

Please guide me on this.

Thanks in advance.


Try this Java service:

Service: [your folders]:getFirstLastDay
Input: year, month
Output: firstDay, lastDay

IDataCursor pipelineCursor = pipeline.getCursor(); 
int year = IDataUtil.getInt( pipelineCursor, "year", -1); 
int month = IDataUtil.getInt( pipelineCursor, "month", -1); 
if(year==-1 || month==-1) 
 throw new ServiceException("Invalid input. Please supply numeric year and month."); 
month--; // Calendar uses 0-based month. This let's our service use human-friendly 1-based months. 
java.util.Calendar cal = java.util.Calendar.getInstance(); 
cal.set(year, month, 1); 
IDataUtil.put( pipelineCursor, "firstDay", Integer.toString(cal.getActualMinimum(java.util.Calendar.DAY_OF_MONTH))); 
IDataUtil.put( pipelineCursor, "lastDay", Integer.toString(cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH))); 

Dear Rob,

Thx for your soln. I have managed the same using following code in my java service.

  GregorianCalendar prev_month_end_date=new GregorianCalendar(); 
    Date dtFrom = new java.sql.Date((prev_month_end_date.getTime()).getTime()); 
    SimpleDateFormat sdf = new SimpleDateFormat(datePattern); 
    String fromdate=sdf.format(dtFrom); 
    System.out.println("The from date is"+fromdate); 

The problem is solved.