Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / August 2006

Tip: Looking for answers? Try searching our database.

Date Format

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vinnie - 14 Aug 2006 09:01 GMT
Hi,

I have a query that reads in a date field from a table.

I've put 'Month: Format([Date Entered],"mmm-yy"); around the data, as I'm
calculating a monthly sum.

But when I go to sort the data by ascending date, it does it alphabetically.
The same occurs when I export it to excel.

Any ideas how to ensure that when I sort the data by date, it does so?

Thanks!
Allen Browne - 14 Aug 2006 10:45 GMT
It will sort correctly if you put the year before the month number:
   TheMonth: Format([Date Entered],"yyyymm")

A better solution would be to use 2 fields for the year and month, and sort
on that:
   TheYear: Year([Date Entered])
   TheMonth: Month([Date Entered])
These fields will then be numbers (instead of Text like the Format()
function generates), so you will be able to do more with them.

I have also suggested a name other than "Month", so that Access does not
misunderstand the name. (There is a function named Month, so Access can get
confused in a form if you have a field with that name in a form.)

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> I have a query that reads in a date field from a table.
>
[quoted text clipped - 8 lines]
>
> Thanks!
Klatuu - 14 Aug 2006 13:55 GMT
The problem really is that you are asking for the month in text format.
Format(Date,"mmmm-yy") will return
August-06

If you need to display the month in text, you probably what to add a
calcuated field to present that.  Also, I would suggest changing to:
Format(Date, "yyyy-mm")
Which will be 2006-08
Putting the month first means you will get all the January records for all
the years followed by Feb, etc.

01-2005
01-2006
02-2005
02-2006

> It will sort correctly if you put the year before the month number:
>     TheMonth: Format([Date Entered],"yyyymm")
[quoted text clipped - 22 lines]
> >
> > Thanks!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.