Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting a string to a date

Status
Not open for further replies.

afryer

Programmer
Mar 9, 2004
207
GB
Hi all,

I have a string value read in from a file, which I need to either store in a date variable or convert to a date. The string read in is in the format YYYYMMDDHHMMSS, i.e 20060509140900 would be today at 14:09. I have tried using the format function to convert this, i.e

myDateVar = format (myStringVar, "DD/MM/YYYY HH:MM:SS")

When it gets to this line however, I get an "overflow" error. Anyone any ideas how I can get around this?

Thanks
 
You get an overflow because the system regards 20060509140900 as a VERY LARGE number of days after December 30, 1899. Try something like
Code:
X = "20060509140900"
myDateVar = DateSerial ( Val(Left(X,4)), _
                         Val(Mid(X,5,2), _
                         Val(Mid(X,7,2)) + _
            TimeSerial ( Val(Mid(X,9,2), _
                         Val(Mid(X,11,2), _
                         Right(X,2) )

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top