Is there any way to increment the date

Suppose I have a date in the variable is today. lets say

StrDate = 29-Apr-2019

Can I increment is by one to get the next date i.e 30-Apr-2019

Sure, you can use DateTime variable type:

StrDate = convert.toDateTime(“2019-04-29”).addDays(1).tostring

2 Likes

strDatePlus1 = DateTime.ParseExact(strDate,"dd-MMM-yyyy",Nothing).AddDays(1).ToString("dd-MMM-yyyy")

2 Likes

@KarthikByggari what is the type of strDatePlus1 you have taken as I taken DataTime.
but I got this error

image

It is a string.
If you want in datetime, remove the part .ToString("dd-MMM-yyyy")

1 Like

@KarthikByggari Thanks to get the correct output, But it’s in the string type var. How can I convert it into the DataTime?

@balkishan

Convert.ToDateTime(yourStringDate)

1 Like

@lakshman Not work Lakshman, If you see I have attached the screenshot. where 1 highlighted is for OldDate and 2 is for increment by one date but it’s in string type. I want to convert the 2 string type into dateTye format should be same. I want the same format. After conversion into DateType I got the 3 it’s into DateType but format is changed?
image

@balkishan

Try this:

Convert.ToDateTime(yourStringDate).ToShortDateString

image

@lakshman Got the above error.

Left side variable is DataType and right side I taken is StringType Var where my date is in the format 1-May-2019

Same I want to convert into DataType variable.

@balkishan

Could you share this workflow and need to check once.

1 Like

Convert.ToDateTime(Dates).AddDays(j).ToString(“dd-MMM-yyyy”)

where “Dates” and “j” is variable. you can add values to the “j” using assign activity

Suppose I assign Dates variable with “31-Jan-20” and Dates is string type
Dates= “31-Jan-20”
Now I want to increment this Dates variable with one so I will use the below expression
Convert.ToDateTime(Dates).AddDays(1).ToString(“dd-MMM-yyyy”)
if you want to increment the date by 2 the just add integer 2 in AddDays(2)
Convert.ToDateTime(Dates).AddDays(2).ToString(“dd-MMM-yyyy”)

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