Convert a yyyymmdd date format in code

  • Thread starter Laurence Lombard
  • Start date
L

Laurence Lombard

How does one in VBA code convert a date with format yyyymmdd (eg today's
date = 20110505) to a date recognized by Excel. I tried ConvertedDate =
Application.Worksheetfunction.Date(Left(InputDate,4),Mid(Inputdate,5,2),Right(InputDate,2))
but that does not work. It would be easy enough in the spreadsheet, but in
VBA?
Thanks
Laurence
 
C

Claus Busch

Am Fri, 6 May 2011 08:50:33 +0200 schrieb Laurence Lombard:
How does one in VBA code convert a date with format yyyymmdd (eg today's
date = 20110505) to a date recognized by Excel. I tried ConvertedDate =
Application.Worksheetfunction.Date(Left(InputDate,4),Mid(Inputdate,5,2),Right(InputDate,2))
but that does not work. It would be easy enough in the spreadsheet, but in

ConvertedDate =DateSerial(Left(Inputdate, 4), Mid(Inputdate, 5, 2), Right(Inputdate, 2))


Regards
Claus Busch
 
R

Ron Rosenfeld

How does one in VBA code convert a date with format yyyymmdd (eg today's
date = 20110505) to a date recognized by Excel. I tried ConvertedDate =
Application.Worksheetfunction.Date(Left(InputDate,4),Mid(Inputdate,5,2),Right(InputDate,2))
but that does not work. It would be easy enough in the spreadsheet, but in
VBA?
Thanks
Laurence


Where "d" is a date in the format of yyyymmdd:


ConvertDate = CDate(Format(d, "0000-00-00"))
 
L

Laurence Lombard

Thanks Claus and Ron - both very useful replies. I knew there would be ways,
just did not know how to find them.
Laurence
 
R

Ron Rosenfeld

Thanks Claus and Ron - both very useful replies. I knew there would be ways,
just did not know how to find them.
Laurence

Glad to help. Thanks for the feedback.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top