How to convert date format(mm/dd/yyyy) to (dd/mm/yyyy) and also how to change string into date format

while fetching data from excel sheet i m getting the date format (dd/mm/yyyy) but requirement is to change it to (mm/dd/yyyy) format. please help me with this.

1 Like

DateTime.ParseExact(yourdatevariable.toString(), “dd/MM/yyyy”, Globalization.CultureInfo.InvariantCulture)
.ToString(“MM/dd/yyyy”)
Use this in an assign activity!

DateTime.ParseExact(here_your_date.ToString(),“dd/MM/yyyy”,Globalization.CultureInfo.InvariantCulture).ToString(“MM/dd/yyyy”)
and please add system.globalistaion in imports.

Dates.xaml (5.7 KB)

Here is the workflow! :slight_smile:

7 Likes

THANK YOU FOR YOUR HELP

2 Likes

Please mark it as solution :slight_smile:

I also have the same problem, and it is strange that I use exactly your example: Dates.xaml, but instead of working directly on the string, I read it from excel, convert it to string, trim the hrs, minutes, and seconds, but it comes the following error message:
The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.
I have imported the system.globalisation.

Anyway I use a tedious method, but work: using .subString to get the year, month, and date, then append them together to form a new string.

You say you’re converting it to string - what variable type is it when you grab it from excel? If it’s already a datetime, then you can just do YourDateVariable.ToString(“MM/dd/yyyy”)

Also, if you could upload the excel sheet with the date that you’re having trouble with that’d make it easier for us to help

1 Like

Dear Dave,

Very much appreciate and amazed by your prompt response. I attach the file for your reference, and I am quite sure the variable read from excel is converted to string type using .toString, and I can write it by Write Line activity.

Thanks a lot.

Snowman

DateTime - Test.zip (20.9 KB)

Hi Dave,

I take your advice, and I first read the excel data as string, Date1, then convert the sting to a DateTime variable, Date2 = CDate(Date1). Then use your advice Date2.ToString(“yyyy/MM/dd”). It works and is more straight forward.

Thanks

1 Like

For my case I have to convert all dates in all rows for example row(7) to dd.mm.yyyy. Do I have to assign a new variable?