Thread: need some help

    #1
  1. No Profile Picture
    worshipper of DOT
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Halmstad, Sweden
    Posts
    35
    Rep Power
    15
    I'm trying to get a month-on-month function for displaying data from a mysql-db.

    The table i want to extract info from, stores urls and timestamps.

    let's say today is the 15th of march, then i want to display all data timestamped from the 1st of march to the 15th of march, and all data from the 1st of february to the 15th of february.

    the dates are stored like "YYYY-MM-DD hh:mm:ss"

    i'm lost, totally lost...

    can any1 help me?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    16
    I'm a big fan of MySQL's to_days() function although there are other ways to do it, I'm sure.

    // assume timestamp column is called 'stamped'

    >SELECT * FROM table_name
    >WHERE to_days(stamped) BETWEEN
    >(to_days('2000-03-01'))
    >AND
    >(to_days('2000-03-15'));

    // or substitute (to_days(now())); for the last line if today is the upper end of the date limit you want to check.

    Check out the online ref manual for information on the to_days() function as well as other date-time arithmetic functions -> very valuable.

    Hope this is what you're looking for.

    Regards,

    Kyuzo
  4. #3
  5. No Profile Picture
    worshipper of DOT
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Halmstad, Sweden
    Posts
    35
    Rep Power
    15
    it might be of use ...

    how does it handle leap years and stuff?

    thanks anyway.
    /closecut

IMN logo majestic logo threadwatch logo seochat tools logo