473,396 Members | 1,998 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,396 software developers and data experts.

CDate Not Cooperating - Need mm/yyyy format only

37
My goal is to take a date such as 1/1/2010 and convert it to 1/2010 or 1/10, either or. The way I am doing this is by using the format function as follows:

Expand|Select|Wrap|Line Numbers
  1. Format([table].[date],"mm/yyyy")
The problem is this spits out a string and I need this as a date for ordering. The resolution should be to use the cdate function which converts the string to a date such as this:

Expand|Select|Wrap|Line Numbers
  1. CDate(Format([table].[date],"mm/yyyy"))
The problem again is that converting this string spits out the format as a date 1/1/2010. As you can see, I am back to the drawing board.

Is there any way to force a format with cdate? Perhaps cdate is the wrong function in this case.
Aug 7 '10 #1
8 16109
missinglinq
3,532 Expert 2GB
Sorry, but a month and year does not a 'date' make!

Exactly why do you 'need' a 'date' for ordering? A clearer explanation of your problem would probably enable someone here to offer a viable solution.

Linq ;0)>
Aug 7 '10 #2
Jerry Maiapu
259 100+
Someone would definitely wonder why you want to split a date to remove the day portion of the date.
For whatever reason you got if I am on the right track then:

..The following will extract the year and the month portion at a time and combine them to format the result as "mm/yyyy" .

Expand|Select|Wrap|Line Numbers
  1. =Month([date])&"/"&Year([date])
The result/final field should be a text field not Date as
"mm/yyyy" is not recognised as Date.

Hope this helps..

JM
Aug 8 '10 #3
missinglinq
3,532 Expert 2GB
That's the same as the OP already has, using Format(). The problem is that he states he needs the resultant field to be a date, which, as we've both said, it can't!
Aug 8 '10 #4
chopin
37
If this is impossible, then so be it. I found a reasonable solution though:

Expand|Select|Wrap|Line Numbers
  1. CDate(Format([table].[date],"m/yyyy"))
Using the one "m" forces all the dates to start at day one for some reason (but this is a good thing). Thus my output will look like:

1/1/2010
2/1/2010
3/1/2010
etc...

This is a solution that will be good enough for me.
Aug 8 '10 #5
missinglinq
3,532 Expert 2GB
Sorry, chopin, but
Expand|Select|Wrap|Line Numbers
  1. CDate(Format([table].[date],"m/yyyy"))
yields the exact same results as your earlier code
Expand|Select|Wrap|Line Numbers
  1. CDate(Format([table].[date],"mm/yyyy"))
Your 'reasonable solution' is no different from what you started out with. There's nothing magical about using the single m here!

And according to your original post, only having month and year would do, not month, day and year!
Aug 8 '10 #6
chopin
37
I wasn't specifically clear with my original post, but I will explain. Basically I wanted to extract the month and year from each line item, so I can show total monthly results. And I wanted to serially increase the mm/yyyy portion so I can present these results correctly, but I needed a sort, which is why I wanted to convert to a date. With my setup with the double m, it would not start out at day one of the month if I showed the full date (the reason why I wanted to cut off the days in the first place). So with my setup, the date would spit out 1/8/2010, then 2/8/2010 etc, this would really not be correct for me. But then I discovered the single m with the combo "yyyy" automatically starts the day at "1" with cdate, and 1/1/2010, 2/1/2010 actually is the same as 1/2010, 2/2010 etc, which works for me.
Aug 8 '10 #7
NeoPa
32,556 Expert Mod 16PB
There seems to be a number of items of confusion here :
  1. Dates are dates. What is important is that they not be confused with the strings that portray them. Date fields can have default format characteristics, but however they are displayed, makes not one jot of difference to what is stored. Internally, Access stores dates as real numbers. The whole number part refers to the number of days since 30/12/1899. The fractional part indicates the time within the day as a fraction of the whole (.5 indicates noon for instance).
  2. As far as date formats go, there is no practical difference between "m/yyyy" and "mm/yyyy". The only difference at all being that a month before October (10) would show with a leading zero (0) in the latter version but not in the former.
  3. Access will always treat a month date string, that is one without the day specified, as being the first day of the month when converting it to a date. I suspect you discovered this at about the time you tried using the format string "m/yyyy", so associated the two together in your mind. This is not exclusive to this particular format. It works that way generally.
Aug 10 '10 #8
NeoPa
32,556 Expert Mod 16PB
To look at your specific issue, that of grouping records together that share the same month, this can be done in two ways :
  1. Convert the date to a string that only shows the month and year ("m/yyyy" for instance). The GROUP BY would consist of this string result directly.
  2. The same as A above, but converting the result back into a date value. The GROUP BY would consist of this date result directly.
It's really as simple as that when you ignore all the misunderstandings and confusions.

The former is the simpler and would involve :
Expand|Select|Wrap|Line Numbers
  1. GROUP BY (Format([date],'m/yyyy'))
Aug 10 '10 #9

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

Similar topics

6
by: dyw55a | last post by:
How to implement mm/dd/yyyy format for textbox? I have text box with format mm/dd/yyyy. Now I want the cursor i generated whenever user highlight this textbox and whatever user inpu replace one...
1
by: Miso Hlavac | last post by:
hello, I need to change date format from mm.dd.yyyy to dd.mm.yyyy But only for one database. In other databases I need mm.dd.yyyy is it possible set this format permanently??? thanx... miso
3
by: CyberLotus | last post by:
Hi, I wish to validate the date a user has entered against the format dd-mmm-yyyy using the CompareValidator, but it does not work. Does anybody have a simple solution please? Many thanks...
5
by: Ben Williams | last post by:
Hello, I'm hoping i'm posting to the correct newsgroup - this question involves both a SQL database and VB. I am a newbie and i'm writing a program in which one of a handful of fields will have...
13
by: Roy | last post by:
Hi all, I'm creating a project that should always use this date format when displays the dates or create dates. The back end database is a SQL Server and I like to know what is the logical way...
5
by: Jens Jensen | last post by:
Hello, I need to format the current date in C# so it looks like this: 10/4/2006 1:38:53 PM Can somen tell how i do this?
3
by: Eric Layman | last post by:
Hi, In general, how do u configure/script to allow .net to accept date in dd/mm/yyyy format? By default, my sys only allows mm/dd/yyyy format. Eg: Take alook at
2
by: jaydeepsinh | last post by:
Hi, I have a SQL server 2000 as database. From database i want retrive date in dd/mm/yyyy format. i m using .net 1.0 and C#.. Can anyone help me..regarding this. Thanks in advance.
4
by: Ashraf Ansari | last post by:
Hi, How Can I convert MM/dd/yyyy format into dd/MM/yyyy and the date which is converted into dd/MM/yyyy should be in DateTime format. I do not want to store it as a string. Please help ...
3
by: neoupadhyay | last post by:
Hi Friends, I am Using ASP.NET1.1 and i want to convert the system date, in dd/MMM/yyyy format. Earlier i use lblDate.Text = System.DateTime.Now.AddMinutes(30).ToString(); But i want to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.