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

Converting Numbers to Dates

Status
Not open for further replies.

pittypat

Instructor
Sep 29, 2002
12
US
I have what think will be an easy question. I have a date column that is a number field that represent a date and formated in this manner "20010101" for January 1, 2000. I simple want to convert it to a short date format 1/1/01. Thanks for your help.

Quest
 
It's really much better to store dates in Date/Time columns, rather than number columns. I recommend you convert the column to a real date.

Here's some code to do your conversion:
Dim strDate As String, datDate As Date
strDate = CStr([date field])
datDate = DateSerial(Left$(strDate, 4), Mid$(strDate, 5,2), Right$(strDate, 2)

You can then display datDate in whatever date format you like, using the Format property of a form or report.
Rick Sprague
 
I am having the same problem. I need to convert a number to a date but I am new to adding code to an access dbase. Where in my database would I add this code. To the query, the properties of the date field, a module. I hope I am not too elementary for this forum. I have been creating dbase with the wizards for a while but I am trying to learn more about the power feature, and this forum is a great resource for beginer programs. Any direction about adding code would be helpful. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top