By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,027 Members | 1,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,027 IT Pros & Developers. It's quick & easy.

DatePart month problem

P: 58
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
Share this Question
Share on Google+
11 Replies


missinglinq
Expert 2.5K+
P: 3,532
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
Expert 5K+
P: 8,669
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
Expert 2.5K+
P: 3,532
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
Expert 5K+
P: 8,669
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
Expert 2.5K+
P: 3,532
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

P: 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
Expert Mod 10K+
P: 14,534
Try this ...

Format(YourDate,"mmm-yy")
Feb 7 '08 #8

P: 11
Try this ...

Format(YourDate,"mmm-yy")
Thanx Masq... worked great.
Feb 12 '08 #9

MMcCarthy
Expert Mod 10K+
P: 14,534
Thanx Masq... worked great.
You're welcome.
Feb 12 '08 #10

P: 1
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
Expert Mod 15k+
P: 31,615
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.