Skip to main content
March 6, 2009
Answered

Date Compare

  • March 6, 2009
  • 2 replies
  • 465 views
I use sql to order events that have there day, month, year in seperate fields in a database however when I say ORDER By month, day it puts days like 12 & 23 ahead of 3 or 5. Thoughts.
    This topic has been closed for replies.
    Correct answer -__cfSearching__-
    PopcornCoder wrote:
    > it puts days like 12 & 23 ahead of 3 or 5.

    That suggests your "month", "day", "year" columns have a character data type rather than numeric. Strings are sorted differently than numeric columns. Assuming you actually need these extra columns, they should probably be stored as numbers, not strings.

    2 replies

    Inspiring
    March 6, 2009
    quote:

    Originally posted by: PopcornCoder
    I use sql to order events that have there day, month, year in seperate fields in a database however when I say ORDER By month, day it puts days like 12 & 23 ahead of 3 or 5. Thoughts.

    My thoughts are that if your db has the requisite date functions, it's better to use them than to store day, month, and year in separate fields.
    Inspiring
    March 6, 2009
    what's the data type of the month and day columns in your db?

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    -__cfSearching__-Correct answer
    Inspiring
    March 6, 2009
    PopcornCoder wrote:
    > it puts days like 12 & 23 ahead of 3 or 5.

    That suggests your "month", "day", "year" columns have a character data type rather than numeric. Strings are sorted differently than numeric columns. Assuming you actually need these extra columns, they should probably be stored as numbers, not strings.