Date Custom Format

C

Cathy

Using DatePart("dd",Now()) should return 01 for Jan.
Error message "Invalid Procedure Call". Same true for
many other custom date formats. Anybody run into this?
 
J

John Vinson

Using DatePart("dd",Now()) should return 01 for Jan.
Error message "Invalid Procedure Call". Same true for
many other custom date formats. Anybody run into this?

No, DatePart should NOT do this. "dd" is a Format, but not a valid
argument to DatePart. See the online help in the VBA editor for
DatePart. The DatePart and Format functions use different arguments.

To get a textstring 01 for January, use

Format(Date(), "mm")

or for "19" for January 19, use

Format(Date(), "dd")

(You can use Now() instead of Date() but there's no point; Now()
returns the current date and time accurate to microseconds, and you
only want the date portion).
 
V

Van T. Dinh

If you want the month as a *Numeric* value:

?DatePart("m", Now())
1

or

?Month(Now())
1


If you want the month as a *String* of format "mm":

?format(Now(), "mm")
01


Actually, you should use Date() rather than Now().

See Access VB Help on the functions I used.

HTH
Van T. Dinh
MVP (Access)
 
D

Dave

(You can use Now() instead of Date() but there's no point; Now()
returns the current date and time accurate to microseconds, and you
only want the date portion).

I thought access only was accurate to Seconds

how do you retrieve the miliseconds part

thanks

Dave
 
J

John Vinson

I thought access only was accurate to Seconds

how do you retrieve the miliseconds part

Frustrating as heck, but you can't. The Date/Time is stored as a
Double Float count of days since midnight, December 30, 1899; since a
Double is accurate to 17 decimal places or so, that's a few
microseconds error over a century. But there's no easy way to get at
the fractional time (other than using CDbl() to extract the number).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top