SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: comparing dates

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    comparing dates

    Well, i have the line
    $datecheck = date('Y-m-d');
    $checking = mysql_query("SELECT * FROM $log WHERE date= '$datecheck'


    it worked fine when the date in the database was the same as $datecheck
    but i changed it to DATETIME lately so it also has the time stored.
    what can i do to compare just the y-m-d without the time?

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    I assume data time is in this format YYYY/MM/DD HH:MM:SS so

    PHP Code:
    date('Y-m-d H:i:s'); 
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The MySQL manual is a wonderful source of answers for such questions:
    http://dev.mysql.com/doc/refman/5.0/...functions.html
    Check out DATE_FORMAT - it's the answer to your question.
    PHP questions? RTFM
    MySQL questions? RTFM

  4. #4
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or just use DATE() on the mysql datetime column, and it'll return just the date.


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
  •