Need to Change Date Format from string to Date

Hi All,

I have to Convert a excel cell value to particular date format.
Input: Fri Jan 20 00:00:00 2022
I need an output in this format(dd/MM/yyyy hh:mm:ss) 20/01/2022.
Please help me with this question.

Regards,
Manoj

@manojmanu.rpa Cdate(your_variable).Tostring(dd/MM/yyyy hh:mm:ss)

@indra thanks for your reply, But there is a weekday in input how can i manage that one.

Regards,
Manoj.

@manojmanu.rpa Can you elaborate what output you are expecting from excel cell

Hi @manojmanu.rpa
formattedDate = CDate(your_variable).ToString(“dddd, dd/MM/yyyy hh:mm:ss”)
This will output a string in the format: “Friday, 20/01/2022 00:00:00”

@indra @Shanmathi Consider this one as Input Fri Jan 20 00:00:00 2022 and the output need to come 20/01/2022 00:00:00, without weekday.

Thanks,
Manoj.

HI @manojmanu.rpa

Try with this expression

DateTime.ParseExact(System.Text.RegularExpressions.Regex.Replace("Fri Jan 20 00:00:00 2022","^\S{3}\s",""),"MMM dd hh:mm:ss yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy hh:mm:ss")

image

Regards
Gokul

In addition to:

In general we would recommend to use ParseExact for converting the string into a dateTime
Afterwards we can reformat as needed

DateTime.ParseExact(YourInputString, YourFormat, System.Globalization.CultureInfo.InvariantCulture)

Format parts (in/out) are as:
grafik


Still we would recommend to check if the Time part is really breaking Month / year in the Position

Kindly note: Friday 20th Jan 2022 does not exist, it was a Thursday so parsing this date will fail
grafik

2 Likes

Try the below given expression,

DateTime.ParseExact(yourdatevariable.toString(),“ddd MMM dd hh:mm:ssyyyy”,Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy hh:mm:ss”)

Hello,
Please check using this expression
DateTime.ParseExact(“Thu Jan 20 00:00:00 2022”,“ddd MMM dd hh:mm:ss yyyy”,system.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

Note: Please verify the week day first On Jan 20 2022 there is thursday. and try

1 Like

Hi @manojmanu.rpa ,

Take a look on this.

Regards
Balamurugan.S

@Gokul001 Thanks, it’s working

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