To log a user in today, use the following syntax. Here we are expecting your datetime field to be of string type -
select yourColumnName1,yourColumnName2,yourColumnName3,...N from youTableName WHERE STR_TO_DATE(yourColumnName1, ‘format’') =CURDATE();
Suppose we have the following "DateEqualToday" table which stores the first and last name of the user along with the login date -
+------+------------+-----------+------------+ | Id | First_Name | Last_Name | LoginDate | +------+------------+-----------+------------+ | 1 | James | Smith | 20-12-2018 | | 2 | Carol | Taylor | 21-12-2017 | | 3 | John | Smith | 21-12-2018 | | 4 | Maria | Garcia | 22-12-2018 | | 5 | Mike | Davis | 21-12-2018 | | 6 | Bob | Wilson | 21-12-2018 | +------+------------+-----------+------------+ 6 rows in set (0.00 sec)
here It is a query that filters users logged in today. In this query compare your date with curdate() function as curdate() only gives the current date -
mysql> select Id,First_Name,LoginDate -> from DateEqualToday WHERE STR_TO_DATE(LoginDate, '%d-%m-%Y') =CURDATE();
+------+------------+------------+ | Id | First_Name | LoginDate | +------+------------+------------+ | 3 | John | 21-12-2018 | | 5 | Mike | 21-12-2018 | | 6 | Bob | 21-12-2018 | +------+------------+------------+ 3 rows in set (0.00 sec)
The above is the detailed content of MySQL chooses to get the user logged in today?. For more information, please follow other related articles on the PHP Chinese website!