Rahul Gupta
Rahul Gupta

Reputation: 1802

convert mmmdd,yyyy string into date VBA

How can I convert string mmmdd,yyyy (Apr16,2015) into date format? Cdate and datevalue does not work here Thanks in advance.

Upvotes: 1

Views: 247

Answers (2)

jbay
jbay

Reputation: 126

Often I use the following methods.

dateStr = "Apr16,2015"
Yr = right(dateStr,4)
Mnth = left(dateStr,3)
Dy = mid(dateStr,4,5)
x = DateSerial(Yr,Mnth,Dy)

or

x = DateSerial(Year(dateStr), Month(dateStr), Day(dateStr ))

Upvotes: 0

Alex K.
Alex K.

Reputation: 175766

"Apr 16 2015" is parsable so:

dateStr = "Apr16,2015"
?cdate(left$(dateStr, 3) & " " & mid$(dateStr, 4, 2) & " " & right$(dateStr, 4))
16/04/2015 

Upvotes: 3

Related Questions