
- 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 query to add days with interval of 45 days and display the output in a new column
For this, you can use date_add(). Let us first create a table −
mysql> create table DemoTable1930 ( DueTime datetime ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1930 values('2017-10-21'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1930 values('2019-12-14'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1930 values('2018-11-26'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1930 values('2014-06-16'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1930;
This will produce the following output −
+---------------------+ | DueTime | +---------------------+ | 2017-10-21 00:00:00 | | 2019-12-14 00:00:00 | | 2018-11-26 00:00:00 | | 2014-06-16 00:00:00 | +---------------------+ 4 rows in set (0.00 sec)
Here is the query to add days −
mysql> select DueTime,date_add(DueTime, interval 45 day) as ManyDays from DemoTable1930;
This will produce the following output −
+---------------------+---------------------+ | DueTime | ManyDays | +---------------------+---------------------+ | 2017-10-21 00:00:00 | 2017-12-05 00:00:00 | | 2019-12-14 00:00:00 | 2020-01-28 00:00:00 | | 2018-11-26 00:00:00 | 2019-01-10 00:00:00 | | 2014-06-16 00:00:00 | 2014-07-31 00:00:00 | +---------------------+---------------------+ 4 rows in set (0.00 sec)
- Related Articles
- How to add a year and two days to a date with a single MySQL query?
- MySQL add days to a date?
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
- MySQL Datetime to add days?
- MySQL query to group by names and display the count in a new column
- Fetch records from interval of past 3 days from current date in MySQL and add the corresponding records
- MySQL query to count occurrences of distinct values and display the result in a new column?
- MySQL query to count days in date range with start and end date
- Add a new column and index to an existing table with ALTER in a single MySQL query?
- Add 11 days to current date in MySQL
- Add 30 days to a value in a MySQL table?
- Add 30 days to date in a MySQL table with arrival date records
- MySQL query to get the length of all columns and display the result in a single new column?
- MySQL SELECT to add a new column to a query and give it a value?
- How to round MySQL column with float values and display the result in a new column?

Advertisements