Hi,

I'm trying to compare two dates - today's date and a date in the database - to see if the database date is 6 months ago or not.

Here is a snippet of the query:

Select curdate(), DATE_SUB(CURDATE(), INTERVAL 6 MONTH), ...

I've noticed that CURDATE() is returning '2005-02-02 00:00:00' on mysql running locally on my laptop.

Does anyone know why this is returning the date in YYYY-MM-DD HH:MM:SS instead of just YYYY-MM-DD?? It's driving me nuts because I can't make a proper comparision since the value in the database is YYYY-MM-DD.

This problem just seemed to arise today as I've had this query run before and work fine.

Thanks.

Rob

P.S.
If anyone needs to know, I'm running v.3.23.22-beta of MySQL.

    Instead of using mysql timestamp, if that is what you are doing, use time() with an INT field or CHAR field when inserting data. Then you can use the following.

    $check_date = time()-(15724800); // Now - 182 days
    $sql = "SELECT * FROM tablename WHERE field = $check_date";

      Thanks, but that would require changing a number of very sensitive queries.

      I've used the CURDATE() function many times and this is the first time it's done something weird like this.

      Any other ideas?

        I don't know if it matters but I'm running this script on my windows machine, not unix.

          Maybe your computer wants to tell you that its about time to update mysql to more up to date version? 😉

            I would love to update to MySQL 4.1 however all the servers that I usually publish sites to are running 3.23 - so I'd rather not upgrade for compatibility reasons.

              I second you rgraves on the mysql version. I run 3.23 also because I develop for others and most hostings are running 3.23.

                Write a Reply...