Get dates between two date input

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

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

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

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

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)

1 Like

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

1 Like

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

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

Regards,
Holger

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