Split date in format dd/mm/yy into variables day = dd, month = mm, year = mm

Date in string variable saved as dd/mm/yy.

I need to save each individual element with their own variable names.
day = dd, month = mm, year = yy

First convert string into DateTime type.

DateTime dt = DateTime.ParseExact(strDate,"dd/MM/yy",System.Globalization.CultureInfo.InvariantCulture)

day = dt.Day
month = dt.Month
year = dt.Year
2 Likes

Do I do this using write line activity or assign activity?

All are assign activities.
Create variables and assign it with the expression given in the previous post.

myDate = 25/02/2019

DateTime myDate = DateTime.ParseExact(strDate,“dd/MM/yy”)
day = myDate.Day
month = myDate.Month
year = myDate.Year

Is this correct?

Yes.

Hi @KarthikByggari ,

just a concern…

For the below to work, shouldn’t the date format be like this "02/22/2019"?

DateTime dt = DateTime.ParseExact(strDate,"MM/dd/yyyy",System.Globalization.CultureInfo.InvariantCulture)

This works exactly when the date format is in the above mentioned MM/dd/yyyy format for me.

1 Like

From the original post, it explicitly mentioned the date format is in dd/mm/yy
So in the DateTime.ParseExact, we have to use the same format.

1 Like

Thanks bro!! :slight_smile:

1 Like

I did what you said but I keep getting an error. The programme is reading from a spreadsheet and for each row which contains a date new day, month, year variables are saved.

image

image