
- 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
Find the number of logins between two dates in MySQL
Use BETWEEN to find the logins between two dates. Let us first create a table −
mysql> create table DemoTable ( Login datetime ); Query OK, 0 rows affected (0.66 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-08-10'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2019-08-12'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2019-08-20'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2019-08-24'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------------+ | Login | +---------------------+ | 2019-08-10 00:00:00 | | 2019-08-12 00:00:00 | | 2019-08-20 00:00:00 | | 2019-08-24 00:00:00 | +---------------------+ 4 rows in set (0.00 sec)
Following is the correct query for MySQL date between −
mysql> select count(*) from DemoTable where Login between '2019-08-12' and '2019-08-24';
This will produce the following output −
+----------+ | count(*) | +----------+ | 3 | +----------+ 1 row in set (0.05 sec)
- Related Articles
- Find number of days between two given dates in C++
- How to find the number of days and number of weeks between two dates in R?
- Perform MySQL search between two dates
- Python program to find number of days between two given dates
- Select the date records between two dates in MySQL
- Get the SUM of records between two given dates in MySQL
- How to query between two dates in MySQL?
- Finding Number of Days Between Two Dates JavaScript
- What is the way to find business days between two specified dates in MySQL?
- PHP program to find the total number of date between any two given dates
- Find objects between two dates in MongoDB?
- How to get the number of seconds between two Dates in JavaScript?
- How to get the number of days between two Dates in JavaScript?
- Find the difference between dates in the form of months with MySQL
- How to get number of quarters between two dates in Java

Advertisements