Coax the DatePart Function into Two-Digit Month Output?

  • Thread starter Thread starter tbl
  • Start date Start date
T

tbl

Is there a way to use the DatePart Function to return the
month as a two digit number, instead of just one digit. I'd
like the result to be more "sort-friendly".

I've tried every variation using "m"s that I could think of,
but no joy.
 
tbl said:
Is there a way to use the DatePart Function to return the
month as a two digit number, instead of just one digit. I'd
like the result to be more "sort-friendly".

I've tried every variation using "m"s that I could think of,
but no joy.


look at the format() function probably. i think "00" would do it if all
you have is the month number. otherwise format "MM/DD/YYYY". that is
just off the top of my head you will want to verify that.

--
Charles E. Vopicka's (Chuck) : (e-mail address removed)

Database Management, GIS Specialist and Research Assistant

Forest Biometrics Research Institute
University of Montana - College of Forestry and Conservation
Missoula, MT 59812
United States of America

Phone:
(406)243-4526
(406)243-4264
(406)549-0647 (Home)

:-) HAVE A NICE DAY (-:

"UNLESS" (The Lorax, by Dr. Seuss)
 
Is there a way to use the DatePart Function to return the
month as a two digit number, instead of just one digit.

Just use either

Month([datefield])

to get a *number* - not a text string - which will sort correctly.

Or if you need a text string (for export maybe?) don't use DatePart at
all - instead use

Format([datefield], "mm")

to get a two-byte text string such as "01" or "12".

John W. Vinson[MVP]
 
Back
Top