473,406 Members | 2,769 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,406 software developers and data experts.

Problem Sorting Dates

I made a query where the first column pulls a date field. I want the column in the query to sort by ascending date. I have confirmed that the format of the field in the actual table is set as 'Short Date.' However, when the query is executed I get:

10/12/2006
9/6/2006
9/7/2006

instead of:

9/6/2006
9/7/2006
10/12/2006

The problem then carries over to my report.

How do I make it so the report will come out like the second example?
Oct 26 '06 #1
11 20126
EdDale
3
Open the report in Design View, Under the View Tab select Sorting and Grouping.
Put the name of your date field under Filed/Expression
Select Ascending under Sort Order

Hope this helps

Dale
Oct 26 '06 #2
NeoPa
32,556 Expert Mod 16PB
Firstly, ensure that the query outputs the Date data in a Date format.
Secondly, organise the sorting for the report via 'Sorting and Grouping' within the Report design.

If you post your SQL we can see if there are any obvious problems.
Oct 26 '06 #3
Thank you for both of your replies. However, I am still not getting the output I need. I believe the commend about the query outputing in the correct date format is where the problem lies. You said that the SQL might help.

I am actually working with a nested query. The first query is:

SELECT DISTINCTROW Format$(tblDayInfo.Date,'Short Date') AS [Date By Day], Sum(tblDayInfo.TotalHours) AS [Sum Of TotalHours], Count(*) AS [Count Of tblDayInfo]
FROM tblDayInfo
GROUP BY Format$(tblDayInfo.Date,'Short Date')
ORDER BY Format$(tblDayInfo.Date,'Short Date');

And the second query is (this one feeds the report I am needing to sort:

SELECT [tblDayInfo Query].[Date By Day], [tblDayInfo Query].[Sum Of TotalHours], tblTotalofTicketsDay.[Sum Of TicketQty], tblTotalofTicketsDay.[Count Of tblTruckingDtl], [tblDayInfo Query].[Count Of tblDayInfo], [Sum Of TotalHours]/[Count Of tblTruckingDtl] AS [Hr/Ld], [Sum Of TicketQty]*7.75 AS DaysTot, [DaysTot]/[Sum Of TotalHours] AS [$/Hr]
FROM [tblDayInfo Query] INNER JOIN tblTotalofTicketsDay ON [tblDayInfo Query].[Date By Day] = tblTotalofTicketsDay.[Date By Day]
ORDER BY [tblDayInfo Query].[Date By Day];

I am noticing now that there is no 'Short Date' at the end of the ORDER BY line of the second query. Is this my problem?
Oct 27 '06 #4
NeoPa
32,556 Expert Mod 16PB
Just leaving for home....
But noticed two things.
1. ORDER BY should be before GROUP BY (I'm pretty sure)
2. You're using the Format$() function which will return a string.

Sorting by the string will give you an alphanumeric sort.
You can SELECT the format() (avoid using Format$) of the date but better to GROUP & ORDER BY the date in date format.
...Of course, if you SELECT the Format() - you will still have the problem in the report, so best not to use Format() at all in the query.
Oct 27 '06 #5
I attempted to reverse the order on the Group By and Order By and got an error.

I also attempted to remove the Format as you suggested, however, I believe I need to replace it with something else in order to get it to work. Do you have any suggestions. I didn't intentionally put the Format into it. I created the queries in design view and did want them to show up as dates.

Could I beg more help with how to replace the Format syntax?

Thanks in advance!
Oct 27 '06 #6
PEB
1,418 Expert 1GB
Hi,

Do not use the Format function only in ORDER BY clause

Juste like:

ORDER BY tblDayInfo.Date;

And if tblDayInfo.Date has a Date/Time format your report will function correctly

If it's a text so the situation is different and You should use a conversion function Cvdate():

ORDER BY Cvdate(tblDayInfo.Date);

:)
Oct 27 '06 #7
NeoPa
32,556 Expert Mod 16PB
How did I get the WHERE & ORDER BY clause positions mixed up?
You may well ask - My bad.

Now, I've just seen that PEB has snuck in there with an answer which is pretty well what you need.
The Format() (I'd still use Format() rather than Format$() mind you) of the data is required as it has to match exactly the [Date By Day] field in [tblTotalofTicketsDay].
The GROUP BY clause should really keep the Format() too but the ORDER BY clause should refer to the naked date before any manipulation.
The GROUP BY really only needs the Format() if it stores times as well as the basic date, but it is more thorough code to keep it anyway.
Oct 27 '06 #8
Thank you much. It worked well. Is there any reason, though, that the correction didn't carry into the second part of the nested query? What I mean is, now I am getting the correct sort at the end of the first query, but not at the end of the second or in the report?
Oct 28 '06 #9
NeoPa
32,556 Expert Mod 16PB
If you remember, the [Date By Day] fields are both formatted into text strings.
Therefore,
Expand|Select|Wrap|Line Numbers
  1. ORDER BY [tblDayInfo Query].[Date By Day];
at the end, sorts it by the text string which looks like a date.
I suppose I should add that, to sort by date here the last line should be :-
Expand|Select|Wrap|Line Numbers
  1. ORDER BY CDate([tblDayInfo Query].[Date By Day]);
Oct 28 '06 #10
PEB
1,418 Expert 1GB
Yeah if the field isn't Date/Time type

This will help

ORDER BY CVDate([tblDayInfo Query].[Date By Day]); AS last line

:)
Oct 28 '06 #11
That worked. Thank you.
Oct 30 '06 #12

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

Similar topics

6
by: bissatch | last post by:
Hi, I am about to write an application that will display all pdf files in a folder and display them by file name in order of date. Is there an easy way of doing this? I was thinking about...
1
by: John Taylor | last post by:
I have a ListCtrl with 5 columns. The first 4 columns are either strings or integers, but the last column is a string in the format of MM-DD-YYYY. I searched google and also read over the...
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....
17
by: Matt Kruse | last post by:
I'm looking for the best JS/CSS solution to add functionality to tables. The only browser which needs to be supported is IE5.5+, but no activeX can be used. to be able to do: - Fixed header row...
22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
18
by: Scott | last post by:
I have a collection where the items in the collection are dates. I want to iterate over the collection and build a value list string for the rowsource of a listbox. The dates in the collection are...
5
by: Randy | last post by:
I am having a sorting problem on a form. No subforms. Continuous Page Main Form. The query works fine pulling up a datasheet but when I attach it to a button on a form. It brings up today's...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
2
by: pruebauno | last post by:
I am currently working on a tricky problem at work. I googled around a bit, but "time intervals" did not come up with anything useful. Although I have some rough idea of how I could solve it, I...
5
by: Mike | last post by:
I have several datagirds that allow sorting on two date columns. The sorting works but its not showing the newest date first when I sort. For example if I have dates in my column as 01/01/2008...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.