Add 31 days to a DateTime Variable

Hello,

I am trying to add 31 days to a DateTime variable (MinStartDate) but the calendar year and month are not updating correctly. i.e. the MinStartDate is 04/03/2024 and I keep getting 04/04/2024.

Dateadd(“d”,31,MinStartDate).ToString(“dd/MM/yyyy”)

Thank you!

Hi @peterrb

Assign: MinStartDate = "04/03/2024"
Assign: StartDate = DateTime.ParseExact(MinStartDate , "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture)
 
Assign: NewDate = MinStartDate.AddDays(31)
 
Log Message: NewDate.ToString("dd/MM/yyyy")

Specify the output what you need so that I will change the syntax accordingly.

Regards

I need the output to read 05/04/2024, basically 31 calendar days after the MinStartDate with month and year updating based on a calendar.

Hi @peterrb

Try this:

Assign: MinStartDate = "04/03/2024"
Assign: StartDate = DateTime.ParseExact(MinStartDate , "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
 
Assign: NewDate = MinStartDate.AddDays(31)
 
Log Message: NewDate.ToString("MM/dd/yyyy")

Regards,

My assign activity for StartDate is giving me the following error. My MinStartDate variable is a DateTime.

Hello,

Check that the type of your StartDate variable is of type system.datetime

Yes
image

What is the type of MinStartDate?

The same System.DateTime

So you don’t need to do ParseExact, just assign StartDate = MinStartDate.addDays(31)

Thank you for all of your help!

1 Like

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