SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    \m/\m/ karinne's Avatar
    Join Date
    Dec 2002
    Location
    Aylmer, QC, Canada
    Posts
    409
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question dates and order by

    i've got a column in my db with the "date" type and the date is entered yyyy-mm-dd ... how do i order by month?

    tia

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SQL is designed to look like natural language... so "order by month" will be "order by month(your_column)" in sql.

  3. #3
    \m/\m/ karinne's Avatar
    Join Date
    Dec 2002
    Location
    Aylmer, QC, Canada
    Posts
    409
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok... order by month(column) works

    why isn't order by day(column) not working? day as is dd in yyyy-mm-dd!?

    edit: and how can i order by day(column), month(column), year(column)?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by karinne
    why isn't order by day(column) not working?
    but it is not working!

    get it? it's not "isn't not working", it's "is not working"

    oh, never mind

    there is no DAY() function

    you want DAYOFMONTH() instead

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    \m/\m/ karinne's Avatar
    Join Date
    Dec 2002
    Location
    Aylmer, QC, Canada
    Posts
    409
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937
    you want DAYOFMONTH() instead
    thanks

  6. #6
    \m/\m/ karinne's Avatar
    Join Date
    Dec 2002
    Location
    Aylmer, QC, Canada
    Posts
    409
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and what about this?

    Quote Originally Posted by karinne
    and how can i order by dayofmonth(column), month(column), year(column)?

  7. #7
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    did you try it? because it should work
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  8. #8
    \m/\m/ karinne's Avatar
    Join Date
    Dec 2002
    Location
    Aylmer, QC, Canada
    Posts
    409
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it only applies the order by dayofmonth(column) and not the others

    this is what i have .....order by dayofmonth(column) asc, month(column) asc, year(column) asc

    thanks for the help

  9. #9
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    is that not what you wanted?

    you're asking for

    13 02 2003
    13 02 2004
    13 02 2005
    13 03 2003
    13 03 2004
    13 03 2005
    13 04 2003
    13 04 2004
    13 04 2005
    14 02 2003
    14 02 2004
    14 02 2005
    14 03 2003
    14 03 2004
    14 03 2005
    14 04 2003
    14 04 2004
    14 04 2005
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  10. #10
    \m/\m/ karinne's Avatar
    Join Date
    Dec 2002
    Location
    Aylmer, QC, Canada
    Posts
    409
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nevermind... i had my order by in the wrong order

    thanks for all your help!


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
  •