
- 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 time period query to fetch date records from interval of 14 weeks from current date?
For this, you can use the BETWEEN keyword. Let us first create a table −
mysql> create table DemoTable ( ArrivalDate date ); Query OK, 0 rows affected (0.93 sec)
Let’s say the current date is 2019-08-31.
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-04-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-03-01'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2019-09-01'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2019-08-31'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-06-30'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2019-06-01'); 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 −
+-------------+ | ArrivalDate | +-------------+ | 2019-04-21 | | 2019-03-01 | | 2019-09-01 | | 2019-08-31 | | 2019-06-30 | | 2019-06-01 | +-------------+ 6 rows in set (0.00 sec)
Following is the query to time period query −
mysql> select *from DemoTable where ArrivalDate between date_sub(curdate(),interval 14 week) and curdate();
This will produce the following output −
+-------------+ | ArrivalDate | +-------------+ | 2019-08-31 | | 2019-06-30 | | 2019-06-01 | +-------------+ 3 rows in set (0.00 sec)
- Related Articles
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
- Fetch records from interval of past 3 days from current date in MySQL and add the corresponding records
- MySQL query to select date >= current date - 3 weeks?
- MySQL query to fetch the latest date from a table with date records
- Select a column if condition is met in MySQL to fetch records from current date and current date + 1
- Comparison of varchar date records from the current date in MySQL
- Calling NOW() function to fetch current date records in MySQL?
- MySQL query to fetch records before currentdate + 2 weeks?
- MySQL query to fetch date more recent than 14 days?
- MySQL query to get the current date records wherein one of the columns displays current date
- MySQL query to retrieve current date from a list of dates
- MySQL query to insert current date plus specific time?
- Find the difference between current date and the date records from a MySQL table
- UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
- MySQL query to get the current date from the list of dates

Advertisements