Home > Database > Mysql Tutorial > body text

How can we add days/seconds to date stored in column of MySQL table?

WBOY
Release: 2023-09-02 08:53:08
forward
764 people have browsed it

How can we add days/seconds to date stored in column of MySQL table?

Two functions can be used for this purpose and in these two functions we need to provide column name as parameter along with INTERVAL keyword. The function is as follows -

DATE_ADD() function

The syntax of this function is DATE_ADD(date, INTERVAL expression unit). This can be demonstrated with an example using data from table 'collegedetail' -

mysql> Select estb, DATE_ADD(estb, INTERVAL 10 DAY) from collegedetail;
+------------+---------------------------------+
| estb | DATE_ADD(estb, INTERVAL 10 DAY)       |
+------------+---------------------------------+
| 2010-05-01 | 2010-05-11                      |
| 1995-10-25 | 1995-11-04                      |
| 1994-09-25 | 1994-10-05                      |
| 2001-07-23 | 2001-08-02                      |
| 2010-07-30 | 2010-08-09                      |
+------------+---------------------------------+
5 rows in set (0.00 sec)
Copy after login

The above query adds 10 days to the date stored in the 'estb' column of the 'collegedetail' table.

ADDDATE() function

The syntax of this function is ADDDATE (date, INTERVAL expression unit). This can be demonstrated with an example using data from table "collegedetail" -

mysql> Select estb, ADDDATE(estb, INTERVAL 10 DAY) from collegedetail;
+------------+--------------------------------+
| estb       | ADDDATE(estb, INTERVAL 10 DAY) |
+------------+--------------------------------+
| 2010-05-01 | 2010-05-11                     |
| 1995-10-25 | 1995-11-04                     |
| 1994-09-25 | 1994-10-05                     |
| 2001-07-23 | 2001-08-02                     |
| 2010-07-30 | 2010-08-09                     |
+------------+--------------------------------+
5 rows in set (0.00 sec)
Copy after login

The above query adds 10 days to the date stored in the "estb" column of the "collegedetail" table.

The above is the detailed content of How can we add days/seconds to date stored in column of MySQL table?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!