cdate date conversion

mendesj1

Registered User.
Local time
Today, 17:27
Joined
Nov 9, 2011
Messages
30
I would like to convert 2013.11.13 which is a string into a date this is what i have so far but it's not working any ideas

2013 year

11 month

13 day of week

Dim strDate As String, dteConvertedDate As Date

strDate = 2013.11.13

dteConvertedDate = CDate(Mid$(strDate, 6, 2) & "/" & Left$(strDate, 4) & "/" & Right$(strDate, 8))

MsgBox (dteConvertedDate)
End Sub
 
"Not working" is not very helpful, but this would have to be:

strDate = "2013.11.13"
 
Code:
strDate = "2013.11.13"

dteConvertedDate = CDate(Mid(strDate, 6, 2) &"/"& Right(strDate, 2)&"/"& Left(strDate, 4))
 
Run time error 13
type mismatch

is the error i am receiving
 
A simple replace of . by / should do the trick to be able to convert the date with cdate.
Either an ISO date YYYY/MM/DD or US date MM/DD/YYYY will work with CDate just fine... so you are close and only need a small change.

Failing that try using DateSerial function which may be a bit more obvious to use?

edit: Whoops I type to slow :(
 
"Not working " :

strDate = "2013.01.02"


2013/02/01


"working " :

strDate = "2013.01.13"

2013/01/13
 
strDate = "20130102"

Me.TarStartDate = CDate(Mid(strDate, 7, 2) & "/" & Mid(strDate, 5, 2) & "/" & Left(strDate, 4))

okkkkkkkkkkkkk
 

Users who are viewing this thread

Back
Top Bottom