SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    substring query for ordering results?

    I have a user filled in field for a date range that is checked and required to be in format 02/02/03-04/02/03.

    What I need to do is list these date periods in order. I was thinking since no two periods are allowed to overlap I would try to pull out the last 8 characters, order by the last two first (year) and then order by the first two (month) and I would be all set.

    I am having trouble constructing this in a query though. Anyone have any tips on doing it in a query? Would it be easier to just pull them all and the try to order them in my php afterwards?

    Thanks a ton.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  2. #2
    SitePoint Guru nagrom's Avatar
    Join Date
    Jul 2001
    Location
    Western CT, USA
    Posts
    803
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it'd be best to store each date in its own "datetime" field. some databases will let you do some list-like stuff (which is what you have there, really), but its usually best avoided.

    so i think your choices are:
    A: restructure the table
    B: parse it after you retrieve it, like you said

    i predict A will be less messier than B

  3. #3
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree, you can change your table structure to include two DATE fields.

    Paul S

  4. #4
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, I might have to do that then. I never really cared about them as dates before. It was just one part of my primary key.

    I guess I will split them up and then go in and concatenate the two fields before I use it everywhere.

    Thanks
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."


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
  •