IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

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

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

    Posted Fri November 29, 2002 01:11 PM

    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.

    Cheers,
    Rajesh


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 2.  RE: Webmethod Built in Date Service to get first amp last day of a month

    Posted Mon December 02, 2002 05:08 PM

    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))); 
    pipelineCursor.destroy(); 
    

    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 3.  RE: Webmethod Built in Date Service to get first amp last day of a month

    Posted Tue December 03, 2002 05:22 PM

    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(); 
    prev_month_end_date.add(GregorianCalendar.MONTH,-1); 
    prev_month_end_date.set(GregorianCalendar.DAY_OF_MONTH,prev_month_end_date.getActualMinimum(GregorianCalendar.DAY_OF_MONTH)); 
    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.

    Cheers,

    Rajesh


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods