Convert String to DateTime(String not valid datetime)

Hi,

How to convert the “[2/13/20 22:35:42:846 GMT+05:30]” into datetime variable

Used Datetime.ParseExact(strTime,“MM/dd/yy hh:mm:ss:SSS”,System.Globalization.CultureInfo.InvariantCulture) but giving an exception
String is not a valid Datetime

Thanks and Regards,
Supriya

@supu123

Try this:

        CDate("inputStrDate")

Hii,

Thanks and Regards,
Supriya

is the data coming from the website.

If you remove everything after “:846” then it will work as @lakshman told

1 Like

@supu123 I guess the time what you have is in an Invalid DateTime Format :sweat_smile:

Hi,
The format mentioned is the date time I m getting from the server and I m capturing it in a string variable ,now I want to convert the time into minutes and compare it with 30 minutes

How to do
Need help

Thanks and Regards,
Supriya

@supu123 Does the String Variable Contain “[2/13/20 22:35:42:846 GMT+05:30]” Brackets as well?

Yes but I removed brackets by using substring

Thanks and Regards,
Supriya

@supu123 Do you want just the time or even the Date as well?

Required date as well

Regards,
Supriya

@supu123 Can you do this Check how the below Value appears in a Message Box :
“[2/13/20 22:35:42:846 GMT+05:30]”.replace(“[”,“”).replace(“]”,“”).Substring(0,16)

Thanks and Regards,
Supriya

Hi,
The message box displayed does not contain milliseconds part

Thanks and Regards,
Supriya

@supu123 Do you need that value as well ? :sweat_smile: It will be bit Complicated to Achieve want you want if that is needed

Hii,

It is ok if that is removed

Thanks and Regards,
Supriya

@supu123 Ok then, you can Assign that value to another String and use it like this :
Datetime.ParseExact(anotherString,“M/d/yy HH:mm:ss:”,System.Globalization.CultureInfo.InvariantCulture)

The output of this will be a DateTime

Hi,

image

Thanks and Regards,
Supriya

@supu123 Can you use strTime.Trim instead of just strTime inside of the DateTime.ParseExact

Check with this code,
date.ParseExact(daate.Split()(0),“'['M/dd/yy”,Nothing).ToString(“dd/MM/yy”)

Hi @supermanPunch

I have trim it

Regards,
Supriya