SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Date Ordering in SQL problem

    Having a small problem with the way the Dates are being ordered in SQL.

    Code:
    SELECT COUNT(1) AS Number, YEAR(Date_Time) As [Year], MONTH(Date_Time) as [month], DAY(Date_Time) as [day] 
    FROM LogInc 
    GROUP BY YEAR(Date_Time), MONTH(Date_Time), DAY(Date_Time)
    ORDER BY YEAR(Date_Time), MONTH(Date_Time), DAY(Date_Time) DESC
    This seems to result in my 2004 dates showing up first instead of my 2005 dates.

    Example

    12/31/2004
    12/30/2004
    ....
    2/11/2005
    2/10/2005
    ...
    So on and so forth

    I have tried moving the order of the ORDER BY around but can't seem to get the results i want (the most recent Date at the top of the list). And i also double checked to make sure i set the field as datetime and not something else. Any advice?

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    695
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    ORDER BY YEAR(Date_Time) desc, MONTH(Date_Time) desc, DAY(Date_Time) DESC


Bookmarks

Posting Permissions

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