Get all Dates between "28.11.2019" and "03.01.2020" as String

Hey guys, ich have two dates as String (DD.MM.YYYY), i want to get all Dates between them.

Do you have an smart idea or is there an activity or something?

My first idea was to split the strings at the points, convert the numbers to int32, and compare the numbers and every time they don’t match to count one up and save the result as new Date and loop that all until the Dates match.

But is this the only way or ist there an easier way?

Convert both strings into DateTime datatype - start, end

Create a list of DateTime datatype.

List dates = new List<DateTime>()
DateTime dt;

for (dt = start; dt <= end; dt = dt.AddDays(1))
{
dates.Add(dt);
}

Regards,
Karthik Byggari

1 Like

Thank you for the fast help, that makes it way easier.

But I get the following Error when i try to convert the string “28.11.2019”, can UiPath handle this Format? Or do I understand the Error wrong?

asd

1 Like

Fine
lets take input like
in_date = “28.11.2019”
and
out_date = “03.01.2020”
where in_date and out_date is a string variable

there are totally four steps
–assign activity
–while loop
–assign activity
–writeline activity

the steps involved are
–in a assign activity like this
final_date = Datetime.ParseExact(in_date,“dd.MM.yyyy”,system.globalization.cultureinfo.invariantculture)

where final_date is a datetime variable

–now use a while loop and mention condition like this
final_date > Datetime.ParseExact(out_date,“dd.MM.yyyy”,system.globalization.cultureinfo.invariantculture)

–inside the loop use a assign activity like this
Final_date = Datetime.ParseExact(Final_date,“dd.MM.yyyy”,system.globalization.cultureinfo.invariantculture).AddDays(1)

–now use a write line activity and mention like this
Final_date.ToString(“dd.MM.yyyy”)

Cheers @Lorenz_Goring

Thank you a lot, it worked for me, expect

final_date > Datetime.ParseExact<

It should be “<”, but I guess you only misstyped

And inside the loop I don’t have to convert Finale_Date into Datetime again.

But i got my final result, so thank you a lot for the great help.

1 Like

no worries
Cheers @Lorenz_Goring

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.