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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use DateValue correctly?

Status
Not open for further replies.

aregan1

Programmer
Feb 12, 2002
46
US
Hi everyone -

I am trying to store a field in an Access 2000 table that is defined as a "Short Date".

I started out with a nine digit number (called CourseDate, defined as "double") that looks like this: 103021603. I stripped off the first 3 digits using:
DateNum = Right(CourseDate, 6)

(I've tried defining DateNum as both a string and a long variable, and the results are the same: 021603). So far, so good!

Now I want to convert 021603 to a date that will be eventually be stored as a short date meaning February 16, 2003. I am using:
dtDate = DateValue(DateNum)

I get a "type mismatch" error on the above statement. I have tried defining dtDate as both a date and a variant, but I get the error either way.

How can I go from my original 9 digit "double" number to a valid short date format?

Thanks in advance for your help...

- Anita
 
Try - -

Dim daD as date
Dim stN as string
stN = "103021603"

daD = DateValue(Mid$(stN,4,2) & "/" & Mid$(stN,6/2) & "/" & Right$(stN,2))

AvGuy
 
dim date as somedate

x="103021603"

somedate = cdate(mid(x,4,2) & "/" & mid(x,6,2) & "/" & right(x,2))
 
Thanks to both of you! It works just fine now...

- Anita
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top