Not able to typecast

Hi All,

I need to type cast string to date but I am getting error.
Here is the screenshot of the exception.
image

Anyone have any idea how to resolve this.

Thanks!
Anmol

Try the below code to convert string to date as per your string expression.

 DateTime.ParseExact("Mon Dec 03 12:36:45", "ddd MMM dd HH:mm:ss",
                                       System.Globalization.CultureInfo.InvariantCulture);

By default, it takes the current year.

image

3 Likes

@anmolk171

I have converted your string into date for the format.
<Day of week> <Month> <Year> <hour:minute:seconds>
Mon Dec 03 12:36:45

date_var = Date.ParseExact("Mon Dec 03 12:36:45", "ddd MMM yy hh:mm:ss",System.Globalization.DateTimeFormatInfo.InvariantInfo)

1 Like

@ranjith, @KarthikByggari:
I am getting a error stating that string was not recognized as a valid Date Time..

Actually I was trimming that date string.
Original string is Mon Dec 03 12:36:45 IST 2018 and I want to know how to work with this.

Thanks1
Anmol

Date.ParseExact("Mon Dec 03 12:36:45 IST 2018", "ddd MMM dd HH:mm:ss IST yyyy",
                                       System.Globalization.DateTimeFormatInfo.InvariantInfo)
1 Like

@KarthikByggari: Can you please let me know is this VB.net or C# code

VB.Net (slightly modified based on the reply from ranjit).

In C#,

 DateTime myDate = DateTime.ParseExact("Mon Dec 03 12:36:45 IST 2018", "ddd MMM dd HH:mm:ss IST yyyy",
                                       System.Globalization.CultureInfo.InvariantCulture);
1 Like

Actually I am new to UiPath, So just want to know which language should I learn VB.net or C#.

Thanks!

@anmolk171

Expressions used in uipath were VB.net .

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