{"id":2602,"date":"2018-06-20T18:15:02","date_gmt":"2018-06-21T01:15:02","guid":{"rendered":"https:\/\/database.guide\/?p=2602"},"modified":"2021-01-28T14:11:23","modified_gmt":"2021-01-28T04:11:23","slug":"adddate-examples-mysql","status":"publish","type":"post","link":"https:\/\/database.guide\/adddate-examples-mysql\/","title":{"rendered":"ADDDATE() Examples &#8211; MySQL"},"content":{"rendered":"<p>In <a href=\"https:\/\/database.guide\/what-is-mysql\/\">MySQL<\/a>, you can use the <code>ADDDATE()<\/code> function to add a specified amount of time to a date. For example, you could use it to add 10 days to a given date. You can specify whether to add days, weeks, months, quarters, years, etc. You can also add a time value, such as seconds, microseconds, etc.<\/p>\n<p>The <code>ADDDATE()<\/code> function is a synonym for the <a href=\"https:\/\/database.guide\/date_add-examples-mysql\/\"><code>DATE_ADD()<\/code><\/a> function (they both do the same thing) when using the first syntax listed below.<\/p>\n<p>This article contains examples to demonstrate usage of the <code>ADDDATE()<\/code> function.<\/p>\n<p><!--more--><\/p>\n<h2>Syntax<\/h2>\n<p>You can use this function in the following two ways:<\/p>\n<pre>ADDDATE(date,INTERVAL expr unit)<\/pre>\n<p>Or<\/p>\n<pre>ADDDATE(expr,days)<\/pre>\n<h2>Example 1 &#8211; The First Syntax<\/h2>\n<p>Here&#8217;s an example of using the first form of the syntax.<\/p>\n<pre>SELECT ADDDATE('2018-12-01', INTERVAL 2 DAY) AS Result;<\/pre>\n<p>Result:<\/p>\n<pre>+------------+\r\n| Result     |\r\n+------------+\r\n| 2018-12-03 |\r\n+------------+<\/pre>\n<p>This example adds 2 days to the date supplied by the first argument.<\/p>\n<h2>Example 2 &#8211; The Second Syntax<\/h2>\n<p>This example could be rewritten to the following:<\/p>\n<pre>SELECT ADDDATE('2018-12-01', 2) AS Result;<\/pre>\n<p>Result:<\/p>\n<pre>+------------+\r\n| Result     |\r\n+------------+\r\n| 2018-12-03 |\r\n+------------+<\/pre>\n<p>This uses the second form of the syntax. The second argument is an integer that represents how many days should be added to the date supplied by the first argument. So obviously, this form is only suitable if you want to specify the amount in days.<\/p>\n<p>Note that\u00a0<code>ADDDATE()<\/code> is a synonym for <code>DATE_ADD()<\/code>\u00a0only when the first syntax is being used. The second syntax is only available in\u00a0<code>ADDDATE()<\/code>.<\/p>\n<h2>Example 3 &#8211; Other Date Units<\/h2>\n<p>One benefit of the first form of the syntax is that you can specify whether to add days, weeks, months, years, etc. Here are some examples.<\/p>\n<pre>SELECT \r\n    '2018-12-01' AS 'Start Date',\r\n    ADDDATE('2018-12-01', INTERVAL 2 WEEK) AS '+2 Weeks',\r\n    ADDDATE('2018-12-01', INTERVAL 2 MONTH) AS '+2 Months',\r\n    ADDDATE('2018-12-01', INTERVAL 2 QUARTER) AS '+2 Quarters',\r\n    ADDDATE('2018-12-01', INTERVAL 2 YEAR) AS '+2 Years';<\/pre>\n<p>Result:<\/p>\n<pre>+------------+------------+------------+-------------+------------+\r\n| Start Date | +2 Weeks   | +2 Months  | +2 Quarters | +2 Years   |\r\n+------------+------------+------------+-------------+------------+\r\n| 2018-12-01 | 2018-12-15 | 2019-02-01 | 2019-06-01  | 2020-12-01 |\r\n+------------+------------+------------+-------------+------------+<\/pre>\n<h2>Example 4 &#8211; Time Units<\/h2>\n<p>You can also use <code>ADDDATE()<\/code> to add time units to a date\/time value. Here&#8217;s an example.<\/p>\n<pre>SELECT ADDDATE('2018-12-01 01:00:00', INTERVAL 2 HOUR) AS Result;\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+---------------------+\r\n| Result              |\r\n+---------------------+\r\n| 2018-12-01 03:00:00 |\r\n+---------------------+<\/pre>\n<h2>Expected Values<\/h2>\n<p>The following table shows the valid unit values and their expected format.<\/p>\n<table>\n<thead>\n<tr>\n<th><code>unit<\/code> Value<\/th>\n<th>Expected <code>expr<\/code> Format<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>MICROSECOND<\/td>\n<td>MICROSECONDS<\/td>\n<\/tr>\n<tr>\n<td>SECOND<\/td>\n<td>SECONDS<\/td>\n<\/tr>\n<tr>\n<td>MINUTE<\/td>\n<td>MINUTES<\/td>\n<\/tr>\n<tr>\n<td>HOUR<\/td>\n<td>HOURS<\/td>\n<\/tr>\n<tr>\n<td>DAY<\/td>\n<td>DAYS<\/td>\n<\/tr>\n<tr>\n<td>WEEK<\/td>\n<td>WEEKS<\/td>\n<\/tr>\n<tr>\n<td>MONTH<\/td>\n<td>MONTHS<\/td>\n<\/tr>\n<tr>\n<td>QUARTER<\/td>\n<td>QUARTERS<\/td>\n<\/tr>\n<tr>\n<td>YEAR<\/td>\n<td>YEARS<\/td>\n<\/tr>\n<tr>\n<td>SECOND_MICROSECOND<\/td>\n<td>&#8216;SECONDS.MICROSECONDS&#8217;<\/td>\n<\/tr>\n<tr>\n<td>MINUTE_MICROSECOND<\/td>\n<td>&#8216;MINUTES:SECONDS.MICROSECONDS&#8217;<\/td>\n<\/tr>\n<tr>\n<td>MINUTE_SECOND<\/td>\n<td>&#8216;MINUTES:SECONDS&#8217;<\/td>\n<\/tr>\n<tr>\n<td>HOUR_MICROSECOND<\/td>\n<td>&#8216;HOURS:MINUTES:SECONDS.MICROSECONDS&#8217;<\/td>\n<\/tr>\n<tr>\n<td>HOUR_SECOND<\/td>\n<td>&#8216;HOURS:MINUTES:SECONDS&#8217;<\/td>\n<\/tr>\n<tr>\n<td>HOUR_MINUTE<\/td>\n<td>&#8216;HOURS:MINUTES&#8217;<\/td>\n<\/tr>\n<tr>\n<td>DAY_MICROSECOND<\/td>\n<td>&#8216;DAYS HOURS:MINUTES:SECONDS.MICROSECONDS&#8217;<\/td>\n<\/tr>\n<tr>\n<td>DAY_SECOND<\/td>\n<td>&#8216;DAYS HOURS:MINUTES:SECONDS&#8217;<\/td>\n<\/tr>\n<tr>\n<td>DAY_MINUTE<\/td>\n<td>&#8216;DAYS HOURS:MINUTES&#8217;<\/td>\n<\/tr>\n<tr>\n<td>DAY_HOUR<\/td>\n<td>&#8216;DAYS HOURS&#8217;<\/td>\n<\/tr>\n<tr>\n<td>YEAR_MONTH<\/td>\n<td>&#8216;YEARS-MONTHS&#8217;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>In MySQL, you can use the ADDDATE() function to add a specified amount of time to a date. For example, you could use it to add 10 days to a given date. You can specify whether to add days, weeks, months, quarters, years, etc. You can also add a time value, such as seconds, microseconds, &#8230; <a title=\"ADDDATE() Examples &#8211; MySQL\" class=\"read-more\" href=\"https:\/\/database.guide\/adddate-examples-mysql\/\" aria-label=\"Read more about ADDDATE() Examples &#8211; MySQL\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[68,115,93],"class_list":["post-2602","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-date-functions","tag-dates","tag-functions"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/comments?post=2602"}],"version-history":[{"count":15,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2602\/revisions"}],"predecessor-version":[{"id":2623,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2602\/revisions\/2623"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=2602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=2602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=2602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}