Mysql query: retrieve current date query
database, mysql, php
Solution
You don't need to use PHP, MySQL has a function to get the current date:
SELECT field FROM table WHERE DATE(column) = CURDATE()
Documentation: CURDATE, DATE.
If your column is only ever going to need the date part and never the time, you should change your column type to DATE. If you insist on doing it through PHP, it is the same thing, really:
$today = date('Y-m-d');
$query = mysql_query("
SELECT field FROM table WHERE DATE(column) = '$today'
");
Problem
In mysql database i have this column called: Name: Date Type: datetime I have few values in that column: 2009-01-05 01:23:35 2009-03-08 11:58:11 2009-07-06 10:09:03 How do I retrieve current date? I am using php. in php: ``` <?php $today = date('Y-m-d');?> ``` How to write a mysql query to retrieve all today date data? Should i change the column type to "date", then insert values like "2009-07-06" only, no time values???