
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL Select to get users who have logged in today?
To get the users logged in today, use the below syntax. Here, we are expecting that your datetime field is a string type −
select yourColumnName1,yourColumnName2,yourColumnName3,...N from youTableName WHERE STR_TO_DATE(yourColumnName1, ‘format’') =CURDATE();
Let’s say we have the following “DateEqualToday “ table that stores users first and last name 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 is the query to filter which users have logged in today. In this query, compare your date with curdate() function because curdate() gives only the current date −
mysql> select Id,First_Name,LoginDate -> from DateEqualToday WHERE STR_TO_DATE(LoginDate, '%d-%m-%Y') =CURDATE();
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)
- Related Articles
- List logged-in MySQL users?
- Find the count of users who logged in between specific dates with MongoDB
- How to list all users who are currently logged into the Linux system?\n
- MySQL query to select closest date from today?
- Select all rows except from today in MySQL?
- MySQL query to group data in the form of user login time per hour and get the records of the users logged in the recent hour?
- Get number of users of different type in MySQL?
- MySQL - Select dates that are one week ahead from today?
- MySQL Select Date Equal to Today and return results for the same date?
- How to get the date between TODAY and TODAY-7”?
- Get today's date in (YYYY-MM-DD) format in MySQL?
- SELECT MySQL rows where today's date is between two DATE columns?
- How to get today's date in Java8?
- Get table names using SELECT statement in MySQL?
- Get documents expired before today in MongoDB?

Advertisements