[ACCEPTED]-Mysql query: retrieve current date query-database

Accepted answer
Score: 15

You don't need to use PHP, MySQL has a function 6 to get the current date:

SELECT field FROM table WHERE DATE(column) = CURDATE()

Documentation: CURDATE, DATE.

If 5 your column is only ever going to need the 4 date part and never the time, you should 3 change your column type to DATE. If you 2 insist on doing it through PHP, it is the 1 same thing, really:

$today = date('Y-m-d');
$query = mysql_query("
    SELECT field FROM table WHERE DATE(column) = '$today'
Score: 1

For date time it is not usefull, instead 2 I try this and working...

Today's Visitors!

sql 1 > select user_id from users where last_visit like concat('%' , CURDATE() , '%');

// last_visit coloumn of type 'datetime'

More Related questions