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

Sort dates that are only month and year

68
Hi!
I have a table that has 'Year' and 'Month'. 'Year' is 4-digit, "Month" is 2 digit. In a query, I want to combine it into one field and sort in order.

On everything I've tried, since the day is missing, it thinks it's a text field.
Even though I can get it to look like "02/2006", it sorts it as text (02/2006, 02/2007, 03/2006, 03/2007) instead of 02/2006, 03/2006, 02/2007, 03/2007.

Thank you!
Apr 6 '07 #1
6 3314
Rabbit
12,516 Expert Mod 8TB
Put year first.
Apr 6 '07 #2
maxamis4
295 Expert 100+
my only suggestion at this point is get rid of the / and just combine the dates as a number. Formatting dates is something that usually occurs in the begining. There a dozen tools that will easily let you go restort back to this formatt for report reasons. Such as left([yourdate0, 2) will give you the month. So again suggestion for sorting just leave it as a number.

ps

right([yourdate], 4) will give you the year. Just in case you need it.

That should give you the first two digits of the month
Hi!
I have a table that has 'Year' and 'Month'. 'Year' is 4-digit, "Month" is 2 digit. In a query, I want to combine it into one field and sort in order.

On everything I've tried, since the day is missing, it thinks it's a text field.
Even though I can get it to look like "02/2006", it sorts it as text (02/2006, 02/2007, 03/2006, 03/2007) instead of 02/2006, 03/2006, 02/2007, 03/2007.

Thank you!
Apr 6 '07 #3
NeoPa
32,556 Expert Mod 16PB
You don't make it very clear what format the data is stored in. If it's a Date/Time field then the answer is different from a string or even two separate fields.
Please include the MetaData for your table. Here is an example of how to post table MetaData :
Table Name=tblStudent
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. StudentID; Autonumber; PK
  3. Family; String; FK
  4. Name; String
  5. University; String; FK
  6. Mark; Numeric
  7. LastAttendance; Date/Time
The solution is not difficult. Understanding the question is the problem here.
Apr 12 '07 #4
dk4300
68
Put year first.
Thanks. I ended up saving it as a text field w/ the year first. I should have thought of that, but I was really wanting there to be a way that easy while having it a date field. :)
Thanks!
Apr 24 '07 #5
Rabbit
12,516 Expert Mod 8TB
Thanks. I ended up saving it as a text field w/ the year first. I should have thought of that, but I was really wanting there to be a way that easy while having it a date field. :)
Thanks!
Not a problem.

However, you never said it was a date field. If it was a date field, it would sort properly. You had 2 seperate fields, both numbers, combining them makes it a string with the format month/year. This is not a date field even though it represents a date field. You could convert it to a date field but date fields require a day in addition to month and year.
Apr 24 '07 #6
NeoPa
32,556 Expert Mod 16PB
Thanks. I ended up saving it as a text field w/ the year first. I should have thought of that, but I was really wanting there to be a way that easy while having it a date field. :)
Thanks!
There is of course, but until you respond to post #4 we can't really tell you what it is.
Ironic isn't it.
Apr 25 '07 #7

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

Similar topics

11
by: Amy G | last post by:
I have seen something about this beofore on this forum, but my google search didn't come up with the answer I am looking for. I have a list of tuples. Each tuple is in the following format: ...
9
by: Thomas W | last post by:
I'm developing a web-application where the user sometimes has to enter dates in plain text, allthough a format may be provided to give clues. On the server side this piece of text has to be parsed...
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....
4
by: Dale | last post by:
Hi Everyone, I've got a form that provides a pop-up calendar for users to select dates for requesting jobs to be completed. The calendar works great, but it unfortunately allows users to select...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
3
by: Matt | last post by:
Hello, I have a query that I would like to schedule in DTS. The criteria of this query checks for records in the table that are within the current quarter. Here is what I have. WHERE...
4
by: Russell | last post by:
I have an assignment that I have to complete. I have to write a windows app in C#. Here is the spec: 1/ Date Comparison Build a program that will find the number of days between two dates. You...
12
by: colincolehour | last post by:
I am new to Python and am working on my first program. I am trying to compare a date I found on a website to todays date. The problem I have is the website only shows 3 letter month name and the...
5
by: soni2926 | last post by:
Hi, I have a web application, asp.net and c# done in 2.0, which is going to return rows from the db with dates or certain events. The db is going to have events dates for the entire year, but on...
4
by: jonathan184 | last post by:
Hi I have a perl script, basically what it is suppose to do is check a folder with files. Now the files are checked using a timestamp with the command ls -l so the timestamp in this format is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.