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.


#TechXchangePresenter
 View Only
Expand all | Collapse all

Get dates between two date input

  • 1.  Get dates between two date input

    Posted Wed July 15, 2020 07:53 AM

    Hi Gurus,

    I need to output stringlist of dates in between of my 2 input string.

    input: startDate (string) and endDate (string)
    output: dateRange (stringlist) dates in between those 2 input date

    i.e.
    Input
    startDate = 07/01/2020
    endDate = 07/04/2020

    Output:
    dateRange [0] = 07/01/2020
    dateRange [1] = 07/02/2020
    dateRange [2] = 07/03/2020
    dateRange [3] = 07/04/2020

    I think I may need to create a java service but my knowledge to it is still minimal.

    Can someone share the code for this?

    Regards,
    BG


    #Integration-Server-and-ESB
    #webMethods-io-Integration
    #webMethods


  • 2.  RE: Get dates between two date input

    Posted Wed July 15, 2020 08:59 AM

    Hi,

    Please refer Integration Server built in services guide esp pub.date and pub.string to build your logic. but I doubt your requirement can be built with out of available services.

    Mostly you need to write a java service using java API’s like Calendar/Date and built the logic to extract dates between two string.

    Hope others can direct you better, but from my knowledge this is what I feel needs to be done.

    Regards
    Firoz N


    #webMethods
    #webMethods-io-Integration
    #Integration-Server-and-ESB


  • 3.  RE: Get dates between two date input

    Posted Wed July 15, 2020 10:47 AM

    you can calculate date difference among the start date and end date and increment start date by 1 those many times


    #webMethods-io-Integration
    #webMethods
    #Integration-Server-and-ESB


  • 4.  RE: Get dates between two date input

    Posted Wed July 15, 2020 12:02 PM

    You might want to search the download section of the community for a Package called PSUtilities.
    This one was developed by Professional Services members and contain a lot of helpful services.
    Some of the services there made it into the WmPublic package meanwhile therefore checking the IS Built-In-Services Reference is a good point to start.

    Regards,
    Holger


    #webMethods-io-Integration
    #webMethods
    #Integration-Server-and-ESB


  • 5.  RE: Get dates between two date input

    Posted Wed July 15, 2020 12:07 PM

    I tried to put a pseudocode (for a java service).

    Try this. If you still find difficulty let me know.

    strtDate = 07/01/2020
    endDate = 07/04/2020

    SimpleDateFormat sdf = new SimpleDateFormat(“MM/dd/yyyy”);

    Calendar cal = Calendar.getInstance();

    // better to keep this statement in a try/catch
    cal.setTime(sdf.parse(strtDate));

    String newDate = sdf.format(cal.getTime());

    Loop → until newDate == endDate (string comparision would do)
    cal.add(Calendar.DAY_OF_MONTH, 1);
    String newDate = sdf.format(cal.getTime());

    newDate can be appended to a List (string)


    #webMethods-io-Integration
    #Integration-Server-and-ESB
    #webMethods


  • 6.  RE: Get dates between two date input

    Posted Thu July 16, 2020 04:05 AM

    Hi,

    This is similar to the topic: Calculate date base on input date and minutes or hour difference

    You should look into the “webMethods Integration Server Built-In Services Reference” manual.

    pub.date:compareDates

    WmPublic - Compares two dates and returns the result as an integer.

    pub.datetime:increment

    WmPublic - Increments or decrements a date and time by a specified amount of time.

    I suggest you try something like this pseudocode using FLOW (no Java needed):

    newDate=startDate
    WHILE (pub.date:compareDates(newDate,endDate) >= 0)
    newDate=pub.datetime:increment(newDate,"1 day")
    

    Happy coding


    #webMethods-io-Integration
    #Integration-Server-and-ESB
    #webMethods


  • 7.  RE: Get dates between two date input

    Posted Thu July 16, 2020 05:09 AM

    Hi Guys,

    Appreciate all your inputs. It helped me solved my problem.

    I was able to solve it using flow service.

    What I did was…

    Calculate days difference of startDate and endDate.
    newDate=startDate
    REPEAT (count using days difference)
    IF
    newDate == endDate Do nothing
    ELSE
    Increment newDate by 1
    Append newDate to dateRange(String list)

    Regards,
    BG


    #Integration-Server-and-ESB
    #webMethods
    #webMethods-io-Integration


  • 8.  RE: Get dates between two date input

    Posted Thu July 16, 2020 09:28 AM

    Did you check the results of your code snippet?
    You might be missing startDate in your resultung dateRange list.

    Regards,
    Holger


    #webMethods-io-Integration
    #Integration-Server-and-ESB
    #webMethods


  • 9.  RE: Get dates between two date input

    Posted Thu July 16, 2020 09:33 PM

    Yes, sorry for confusion, I purposely did not get the startDate for my requirement.

    Here’s what I really need.

    Input
    startDate = 07/01/2020
    endDate = 07/04/2020

    Output:

    dateRange [0] = 07/02/2020
    dateRange [1] = 07/03/2020
    dateRange [2] = 07/04/2020

    Regards,
    BG


    #webMethods
    #Integration-Server-and-ESB
    #webMethods-io-Integration