converting text to date

  • Thread starter Thread starter faddrickremo
  • Start date Start date
F

faddrickremo

Dear all,
I have few doubts in vb which I hope can be solved in this
forum,
1) how do i convert the number 820219 to 19/02/1982?
2) i have a textbox placed on a form.
user is free to enter any value in this text box.
but when the user enters a date i wanted to convert the
text to date .

Can somebody help me in rectifying the problem?

bye
faddrick
 
If it's a number (say, lngDate), convert it into a string, then parse it
into its component parts and convert it into a date (say, dtmDate), along
the lines of:

Dim strDate As String
Dim strDay As String
Dim strMonth As String
Dim strYear As String

strDate = CStr(lngDate)
strYear = Left$(strDate, 2)
strMonth = Mid$(strDate, 3, 2)
strDay = Right$(strDate, 2)
dtmDate = DateSerial(1900 + CLng(strYear), CLng(strMonth), CLng(strDay))
 
Thank you very much for the solution.
i didnt get answer for the second question.
can u pl help me in solving my second problem?
bye
faddrick
 
Use the IsDate function to see whether they've entered a date, and then
CDate to convert it to a date if appropriate.
 
"dossstuart" wrote
Where would you input this vb code?

Whereever you want to perform the conversion; or, you can make it a Public
procedure in a standard module and call it from where you want to do the
conversion.
is there a way to convert it in a query ?

Yes, if it is an Access-Jet query, that will work nicely. If it is a query
against linked tables in a server database it will try to bring back every
record to perform the Access calculation and that will likely not be a good
thing, performancewise.

Larry Linson
Microsoft Access MVP
 
Back
Top