Home > Database > Mysql Tutorial > body text

MySQL chooses to get the user logged in today?

PHPz
Release: 2023-08-26 22:05:13
forward
586 people have browsed it

MySQL 选择获取今天登录的用户?

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();
Copy after login

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)
Copy after login

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();
Copy after login

output

+------+------------+------------+
| 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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!