Thread: Date Range

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    20
    Rep Power
    0

    Date Range


    i just inhered a db where the dates are stored as a string so i dont think i can use the between so do my search

    PHP Code:
    $query="select * from table where date_column between "2001-01-01" and "2013-01-12"; 
    so i was going to write it like

    PHP Code:
    SELECT FROM table WHERE 
                    
    (
                        `
    fieldname` = 'createdtime'
                        
    AND 
                        (
                            `
    postvalueLIKE '%2012-12-04%'
                            
    OR `postvalueLIKE '%2012-12-05%'
                        
    )
                    ) 
    i dont really like this but i was wondering how can build the a string of dates between 2 dates
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,453
    Rep Power
    594
    This sounds more like a MySQL question rather than PHP. You might get better results having this thread moved to that forum (click on the red triangle in the upper right).
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    if you have any chance to fix the database, then do it. That's the only real solution. Working with broken data is horrible, especially when it's complicated data like dates.

    If you can't get to the database, you'll have to parse the date strings each time you use them. Use STR_TO_DATE() or something.

    But don't fumble with string comparisions, that'll get you nowhere.

IMN logo majestic logo threadwatch logo seochat tools logo