Convert yyyy-mm-ddThh:mm:ss into date yyyy-mm-dd

hello

i have this value “yyyy-mm-ddThh:mm:ss” in a string from a datatable and i want to convert into a date yyyy-mm-dd so i can use it for a if condition

Any help would be appreciated.

@Roger_CQ
Welcome to the forum

Working with CDate:
grafik
CDate(YourStringVar).toString("yyyy-MM-dd")

As an alternate with having more control over the parsing format we can also do:

In case of date conversion issues also have a look here for some initial analysis strategies:

in both cases i have a error with the conversion string to date. i am trying to assign into a date variable

Hi,

FYI, another solution:

Strings.Left(yourString,10)

or

System.Text.RegularExpressions.Regex.Match(yourString,".*?(?=T)").Value

Regards,

we do not reformat internally the datetime. so it will return a string

Also have a look here for some additional samples
grafik

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