473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 33055
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,834 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,834 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,556 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

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

Similar topics

19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
2
by: Job Lot | last post by:
I have two ComboBox on a form both holding list of months in a year (Jan – Dec). I wan to calculate number of months between Month selected in first combobox and Month selected in second...
5
by: Ataru Morooka | last post by:
Hi, my table has to have a column with the months names (january, february...). When I order it by month it is ordered alphabetically and that's not what I need. Reading this ng I found someone...
4
by: John | last post by:
Hi, I am using a text box to input a date in a form and from that date I want to show a new date in another text box which is one calendar week later. As it is, it works fine untill I reach the...
4
by: J-P-W | last post by:
Hi, I have a system that records insurance policies. If the policy is cancelled then any part of a month insured is deducted from the premium, so a policy that ran for 32 days would get a 10...
3
by: apartain | last post by:
I use DatePart("ww",.Date) to get the number of the week in the year for a weekly time card. The week in the system is beginning Sunday and ending Saturday. Is there any way to make it beginning...
5
by: Seb | last post by:
I want to count activity in a given month. I'm trying to do so with the linq code below however it reports: Error 1 'a' is inaccessible due to its protection level var ActivityByMonths = from a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.