Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2009
    Posts
    5

    Unanswered: How to make months appear in calender order

    How to make months appear in calender order

    SELECT TYear,TQuarter,TMonth,AVG(ChangeClose) AS AverageSorted
    FROM NDX
    GROUP BY TYear,TQuarter,TMonth
    ORDER BY AverageSorted DESC;

    How to write a query to display a single field with the date in the form of day/month/year?

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Add another column representing the month (in numeric form) and sort by that. Just because it is there doesn't mean you have to use it
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Sep 2009
    Posts
    5
    how do you do numeric form

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    You create an expression in the query (put this in a new column in the query).
    ie:
    SomeExpressionName: Format([MyDateFieldName],"m")
    or
    SomeExpressionName: Format([MyDateFieldName],"mm")

    Then sort on that field.

    (Note: you can uncheck the "Show" for the above expression column. Then have another expression column in the query (which is marked to show) and have your date field formatted like you want.
    ie.
    SomeExpressionName: Format([MyDateFieldName],"m/d/yy") => 1/5/09
    or Format([MyDateFieldName],"mm/dd/yyyy") => 01/05/2009
    or Format([MyDateFieldName],"(ddd) mm/dd/yyyy") => (Tue) 01/05/2009
    or Format([MyDateFieldName],"mm/yyyy") => 01/2009
    or Format([MyDateFieldName],"Short Date") => 1/5/2009
    or Format([MyDateFieldName],"mm-dd-yyyy h:nn AM/PM") => 01-05-2009 5:30 PM
    etc...etc...
    Look at the MSAccess help on what letters represent what you want to show (ie. (ddd) would show as (Mon), (Tue), (Wed) and (dddd) would show as (Monday), (Tuesday), (Wednesday) while a (single or double) d or dd represents the day (ie. 1, 2, 3 or 01, 02, 03) etc...etc...
    Last edited by pkstormy; 09-07-09 at 03:03.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Since Format() returns a String, I'd think you'd have to use

    SomeExpressionName: Format([MyDateFieldName],"mm")

    to sort properly, but I'd simply use

    SomeExpressionName: Month([MyDateFieldName])

    because Month() returns an Integer.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    SomeExpressionName: Month([MyDateFieldName])

    ▲ This is how you do "numeric form". Just do this and sort by this column.

    SELECT ...
    FROM ...
    WHERE ...
    ORDER BY Month([MyDateFieldName]);
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •