Mysql query: retrieve current date query

后端 未结 2 1091
误落风尘
误落风尘 2020-12-04 00:37

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-

相关标签:
2条回答
  • 2020-12-04 01:02

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

    Today's Visitors!

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

    // last_visit coloumn of type 'datetime'

    0 讨论(0)
  • 2020-12-04 01:08

    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'
    ");
    
    0 讨论(0)
提交回复
热议问题