SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to select record that create within 3 days

    I have column that keep current date (DATE in mysql) when insert record.

    How to select record that post within 3 days.
    I live in Thailand. My English grammar not well.

  2. #2
    SitePoint Zealot infoxicated's Avatar
    Join Date
    Jun 2001
    Location
    UK
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink

    PHP Code:
    $three_days_ago gmdate("Ymd") - 3
    Select * from mytable where date=$three_days_ago;

    Actually, that might be a bit crap because you need the "-" in the date... I have to go, so I cant give you the extra code right now.. sorry! (Doh!)
    Last edited by infoxicated; Jun 19, 2002 at 10:25.

  3. #3
    SitePoint Addict eddiembabaali's Avatar
    Join Date
    Mar 2001
    Location
    USA, Philadelphia
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT blah, blah_blah FROM table WHERE TO_DAYS(NOW()) - TO_DAYS(date-or-timestamp_col) <= 3;
    cd pub \r; more beer

    Eddie

  4. #4
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Is TO_DAYS() is function in mysql.

    It seem doesn't work.
    I live in Thailand. My English grammar not well.

  5. #5
    SitePoint Evangelist cyngon's Avatar
    Join Date
    Aug 2001
    Location
    Livonia, MI, USA
    Posts
    513
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    TO_DAYS() is a MySQL function. It returns a day number given a date.

    Exactly what query are you trying?

    It looks to me like the SQL eddiembabaali posted should work fine.

  6. #6
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm write wrong code. but now it work.

    Thanks everybody again.
    I live in Thailand. My English grammar not well.


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
  •