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.

2 Likes

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

5 Likes

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

2 Likes

Dates.xaml (5.7 KB)

Here is the workflow! :slight_smile:

11 Likes

THANK YOU FOR YOUR HELP

2 Likes

Please mark it as solution :slight_smile:

2 Likes

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.

1 Like

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)

1 Like

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

2 Likes

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?

Hi @ASHISH.CHAT
(System.Date.today.AddDays(7).Date).ToString(“dd/MM/yyyy”)

what if i have a column of date i want to convert from dd/mm/yyyy to yymm?

@Dave @Snowman @Akhil @Thomas78 @Fabricio.camara @junnieset @loginerror

how to convert date in the format “DD-MMM-YY” OR “DD-MMM-YY” TO DD/MM/YYYY ?
example 26 March 21 to 26/03/2021 or 19 Feb 2021 to 19/02/2021

1 Like

Hi,

new_date = DateTime.ParseExact(string_date.ToString,"DD-MMM-YY", Globalization.CultureInfo.InvariantCulture).ToString("DD/MM/YYYY")
2 Likes

its throwing error … what should be the variable type of new_date string and datetime is not working

new_date should be a datetime variable and string_date should be a string variable.

It looks like there is an error in the ParseExact date format though. Take a look here to see all datetime formats: Custom date and time format strings | Microsoft Docs
26 March 21 would be formatted as “dd MMMM yy” (note the capitalization of M but not d or y, it’s important!) and 19 Feb 2021 would be “dd MMM yyyy”

1 Like

@Akhil Thanks man… It worked & helped… :slight_smile: