Date and time text string to date variable

  • Thread starter Thread starter John Marshall, MVP
  • Start date Start date
John - I haven't followed your earlier threads, but there are two ways you
can convert a "date string" to a "date variable":

(1) If you put the date string into a recognizable format (say,
"mm/dd/yyyy"), you can use the DateValue function to convert it to a date
value:
MyDate = DateValue(Right("YYYYMMDD",2) & "/" & Mid("YYYYMMDD",5,2) &
"/" & Left("YYYYMMDD",4))

(2) You can use the DateSerial function to convert to a date:
MyDate = DateSerial(CInt(Left("YYYYMMDD",4)),
CInt(Mid("YYYYMMDD",5,2)), CInt(Right("YYYYMMDD",2)))
 
Thanks Ken, but the date part works fine, the problem I have is creating a
date variable from two text strings (one has "YYYYMMDD" and the other has
"HH:MM"). From what I have discovered is that I need to load the date string
into a date variable and then create a new string in the format as "Jan 1,
2004" and then combine that with the "HH:MM" string. This is seems like a
lot of work for something that should be easier.

John... Visio MVP

Need stencils or ideas? http://www.mvps.org/visio/3rdparty.htm
Need VBA examples? http://www.mvps.org/visio/VBA.htm
Common Visio Questions http://www.mvps.org/visio/common_questions.htm
 
Sorry...too early in the morning..missed the time feature.

You can use the TimeSerial function to get the time into a fractional
number, then add it to the DateSerial value.

MyDateAndTime = DateSerial(CInt(Left("YYYYMMDD",4)),
CInt(Mid("YYYYMMDD",5,2)), CInt(Right("YYYYMMDD",2))) +
TimeSerial(CInt(Left("HH:MM",2)), CInt(Right("HH:MM",2)), 0)
 
Back
Top