Expecting date output to be 012110, but getting 01/21/2010

M

Mark

Hi All,

Having date issue. I'm trying to attach the date to the end of a file name.
I'm formating my date to exclude the "/". I'm using this, but it comes out
the same. What am I doing wrong?

strDate = DateValue(Format(Date, "000000"))
or
strDate = DateValue(Format(Date, "mmddyy"))

Both return 01/21/2010
 
C

Clifford Bass via AccessMonster.com

Hi,

DateValue() converts the string back into a date.. well.. value. So you
end up going in circles from Date() which is a date value, to the string
"012110" and then to the date value #01/21/2010# and finally back to a string.
This would be the same as

strDate = Date

Try:

strDate = Format(Date, "mmddyy")

Clifford Bass
 
F

fredg

Hi All,

Having date issue. I'm trying to attach the date to the end of a file name.
I'm formating my date to exclude the "/". I'm using this, but it comes out
the same. What am I doing wrong?

strDate = DateValue(Format(Date, "000000"))
or
strDate = DateValue(Format(Date, "mmddyy"))

Both return 01/21/2010

Access is doing exactly what you're telling it to do.
"000000" will always display 6 digits

"mm" will display a 2 digit month even if the month digit is just one
number.
"dd" will display a 2 digit day even of the day is one digit.

Using a date of Jan 5, 2010 or Dec 5, 2009 to illustrate....
Use:
strDate = Format(Date,"mddyy")
for a 1 OR 2 digit month and a 2 digit day.
10510
or
120509

Use strDate = Format(Date,"mdyy")
for a 1 OR 2 digit month and 1 OR 2 digit day.
1510
or
12509

However, looking at the above 12509, is that January 25th or is it
December 5th? How will anyone know a year down the road?

Why don't you make the date value unambiguous:
Format(Date,"mmmddyyyy")

Jan052010
Dec052009
 
C

Clifford Bass via AccessMonster.com

Hi,

Actually, to be unambiguous AND get it to sort correctly AND be easy to
read use:

Format(Date, "yyyy-mm-dd")

Clifford Bass
 

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