Error while converting String variable to Date format

I am getting error While converting the string variable to date format for following methods, please suggest me where i made mistake.

  1. Convert.ToDateTime Method
    Eg:- Convert.ToDateTime(DobStr.ToString)
  2. DateTime.Parse method
    Eg:- DateTime.Parse(DobStr.ToString)

I am able to achieve by using the following expression

DateTime.ParseExact(DobStr,“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture)

Hey!

Try like this:

Assign strDate = Datetime.ParseExact(Strinput.ToString, “MM-dd-yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

NOTE:

Where MM-dd-yyyy is the input format
Where dd/MM/yyyy is the output format

Regards,
NaNi

So use that one.

If a variable’s datatype is string, you don’t need to put .ToString on the end of it

Can you share with us the DobStr Value? e.g. immediate panel screenshot
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

“16/08/2001”

this string is parseable with the mentioned option

grafik

ensure that dd/MM/yyyy format pattern is always matching the format pattern of your string

Convert.toDateTime, DateTime.Parse, CDate will not handle the dd/MM/yyyy format

So, is your topic solved or what is your further open question on this?

2 Likes

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