Using CDate with "MM/dd/yyy"

Hi Experts,

How do I use CDate to convert the string "3/27/2010 01:55 PM GMT" to a date because it does not like the MM/dd/yyyy format.
DColinAsked:
Who is Participating?
 
PryratesConnect With a Mentor Commented:
ups - forgot to declare the variable "s" in the sample.
here is the full code.
Dim s as string = "3/27/2010 01:55 PM GMT"
Dim enUS As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US")
        Dim dt As DateTime = DateTime.Parse(s, enUS)

Open in new window

0
 
ThomasianCommented:
What access does not like is the "GMT" at the end of the string.

Here's the query to remove everything after 'GMT' and convert it to date.

SELECT CDATE(LEFT([txtfield], INSTR(1,[txtfield],'GMT')-1))
0
 
PryratesCommented:
you need to set a proper provider info to convert this date format string

this should do with your string to get a valid DateTime object :)
Dim enUS As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US")
        Dim dt As DateTime = DateTime.Parse(s, enUS)

Open in new window

0
 
ThomasianCommented:
Sorry, when I saw CDate I assumed you were using MS Access. Forgot to look at the zone...
0
All Courses

From novice to tech pro — start learning today.