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!

Formatting Date() 1

Status
Not open for further replies.
Jul 17, 2002
22
US
I need to change the format of the date() function. When i try to use it know it yields mm/dd/yyyy, but I need it to produce yyyymmdd (without dashes).

Does anyone know how to produec the date in this manner?
You help would be greatly appreciated.

soontobefour
 
intYear = DatePart("yyyy", Date)
intMonth = DatePart("m", Date)
intDay = DatePart("d", Date)

MsgBox intRow & intMonth & intDay

Produces what you need. The MsgBox just displays it.

DreamerZ
 
Thank you very much, RJFost and DramerZ. I used Format(Date(),"yyyymmdd") and that worked great. Thanks for your speedy reply and assistance.

soontobefour
 
It must be a version issue because I tried the Format(...) and I received a syntax error.

Take out the () for the Format and doesn't error, but a MsgBox displaying the results of Date still show the /.

I'm using Access 2000.

DreamerZ
 
You'd have to check Microsoft's KB to be sure, but I think it has to do with which version of which Jet engine you're using (e.g., Jet 3.5, Jet 4.0 SP 6, etc.). Over the past few, I've seen formatted dates returned as date-type values, string values & (not for a while) variants. Go figure. If you want a belt-&-suspenders kind of surety, I've seen folks use CDate(Format(Date(),"yyyymmdd")), but then you run the risk of an unexpected system or field format override (i.e., the system [PC] or database field format may massage the return from CDate).

Working with dates in Access is rather like walking through a pasture: 1) always watch your step, & 2) be prepared for some degree of clean-up if you don't follow #1.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top