This will produce 2013-10-29
1 2 3 4 |
SELECT NOW(); // You will get 2010-12-09 17:10:18 SELECT CURDATE(); // You will get 2010-12-09 |
Another example is
1 2 3 |
$query = "INSERT INTO table1 (date, time, operator, status, completed, name, email) VALUES (CURDATE(), CURTIME(), '".$operator."', '".$status."', '".$complete."', '".$name."', '".$email."')"; |
Tomorrows date
1 2 3 |
SELECT CURDATE()+1; |
And some more interesting ways…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
select curdate(); -- 2011-01-31 select cast(curdate() as datetime); -- 2011-01-31 00:00:00 select if('2011-01-31' <= curdate(), 'yep', 'not this time'); -- yep select if('2011-01-31 00:00:01' <= curdate(), 'yep', 'not this time'); -- not this time select if('2011-01-31 01:00:00' <= adddate(curdate(), interval 1 day), 'yep', 'not this time'); -- yep |
And another
1 2 3 |
$result = mysql_query("SELECT * FROM cmdata WHERE date=curdate() and time=DATE_FORMAT(NOW(),'%H')"); |
More info here about other formats like hour etc