
- 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 dates that are one week ahead from today?
To get dates that are one week ahead from today, use DATEDIFF. Let us first get the current date −
mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-12-20 | +------------+ 1 row in set (0.00 sec)
We will first create a table −
mysql> create table DemoTable1990 ( ShippingDate date ); Query OK, 0 rows affected (0.99 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1990 values('2019-12-13'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1990 values('2019-12-21'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1990 values('2019-12-20'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1990 values('2019-12-24'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1990;
This will produce the following output −
+--------------+ | ShippingDate | +--------------+ | 2019-12-13 | | 2019-12-21 | | 2019-12-20 | | 2019-12-24 | +--------------+ 4 rows in set (0.00 sec)
Here is the query to select dates that are one week ahead from today −
mysql> select * from DemoTable1990 where datediff(curdate(),ShippingDate)%7=0;
This will produce the following output −
+--------------+ | ShippingDate | +--------------+ | 2019-12-13 | | 2019-12-20 | +--------------+ 2 rows in set (0.04 sec)
- Related Articles
- MySQL query to select closest date from today?
- Select all rows except from today in MySQL?
- MySQL select distinct dates from datetime column in a table?
- How to select month and year from dates in MySQL?
- MySQL select dates in 30-day range?
- MySQL select query to select rows from a table that are not in another table?
- MySQL Select to get users who have logged in today?
- Select dates between current date and 3 months from the current date in MySQL?
- MySQL query to select rows older than a week?
- Select the date records between two dates in MySQL
- Get the Day of the Week from Today's Date in Java
- Fetch date record that equals today in MySQL
- How to select between/before/after dates in MySQL conditionally?
- SELECT a row by subtracting dates in WHERE in MySQL?
- How to select distinct value from one MySQL column only?

Advertisements