469,366 Members | 2,360 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

DatePart month problem

I am trying to use DatePart to return a two digit month. I would like to see 01, 02, 03, ...10, 11, 12 for the months. How can I do this? I'm sure it has something to do with the format of my date field, but I can't figure out the custom format for it.

Thank you,
ang
Jan 6 '07 #1
11 31832
missinglinq
3,532 Expert 2GB
You can't with DatePart, but you can with format(YourDate,"mm")

format(now,"mm") for instance will return 01
Jan 6 '07 #2
ADezii
8,800 Expert 8TB
I am trying to use DatePart to return a two digit month. I would like to see 01, 02, 03, ...10, 11, 12 for the months. How can I do this? I'm sure it has something to do with the format of my date field, but I can't figure out the custom format for it.

Thank you,
ang
Format$(DatePart("m", #1/6/2006#), "00") ==> 01
Jan 6 '07 #3
missinglinq
3,532 Expert 2GB
I'm curious, why would you want to use 2 functions to do the job that one function can do?
Jan 6 '07 #4
ADezii
8,800 Expert 8TB
I'm curious, why would you want to use 2 functions to do the job that one function can do?
You would never, but apartain specifically stated that he wished to use the DatePart Function.
Jan 7 '07 #5
missinglinq
3,532 Expert 2GB
That's kinda what I figured, but I don't really think he's married to the idea, I think he just thought that DatePart was the only way to pull the month from the date. Of course, you have to wonder why MS won't let you use the "mm" with DatePart the same way as with Format to pull the two digit month designation.

Have a good weekend!
Jan 7 '07 #6
TIonLI
11
I'm curious, why would you want to use 2 functions to do the job that one function can do?
Linq,

Hope you don't mind me sending this question to you direct, but based on above, it seems that you have the answer to my question...

I'm grouping dates by month in a query for purpose of counts and averages on some other fields. Results display month as single digit (i.e. Jan = 1, Feb = 2, etc.). I would like to format the field so I get the month name spelled out, or better yet month-year (i.e. Jan-06, Feb-06, etc.). The auto format in Properties only provides number formats.

Here's what I have for a query field so far: SALE MONTH: DatePart("m",[SALE-DATE])

I tried this with no luck:
DatePart("mmmm",[SALE-DATE])

Thanx in advance.
Feb 6 '08 #7
MMcCarthy
14,534 Expert Mod 8TB
Try this ...

Format(YourDate,"mmm-yy")
Feb 7 '08 #8
TIonLI
11
Try this ...

Format(YourDate,"mmm-yy")
Thanx Masq... worked great.
Feb 12 '08 #9
MMcCarthy
14,534 Expert Mod 8TB
Thanx Masq... worked great.
You're welcome.
Feb 12 '08 #10
Not quite. Format params are case sensitive. Small case "m" returns the minute part of the date, Upper case "M" returns the month.

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
Jan 3 '12 #11
NeoPa
32,185 Expert Mod 16PB
Actually, in VBA, minutes are handled by n and months by m (of either case). The link you posted was for C# in .NET.

I couldn't find anywhere helpful on the web (unfortunately), but the Help System has a page that makes it pretty clear.
Jan 3 '12 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

19 posts views Thread by Lauren Quantrell | last post: by
2 posts views Thread by Job Lot | last post: by
4 posts views Thread by John | last post: by
5 posts views Thread by Seb | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.