{"id":6170,"date":"2017-07-08T00:11:58","date_gmt":"2017-07-08T07:11:58","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=6170"},"modified":"2023-10-14T17:51:09","modified_gmt":"2023-10-15T00:51:09","slug":"mysql-date_sub","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-date-functions\/mysql-date_sub\/","title":{"rendered":"MySQL DATE_SUB() Function"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to subtract a time from a date using the MySQL <code>DATE_SUB()<\/code> function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to MySQL DATE_SUB() function<\/h2>\n\n\n\n<p>The <code>DATE_SUB()<\/code> function subtracts a time value (or an <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-interval\/\">interval<\/a>) from a <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-date\/\">DATE<\/a><\/code> or <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-datetime\/\"><code>DATETIME<\/code><\/a> value. <\/p>\n\n\n\n<p>Here&#8217;s the syntax of the <code>DATE_SUB()<\/code> function:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">DATE_SUB(date,INTERVAL expr unit)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>DATE_SUB()<\/code> function accepts two arguments:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u00a0<code>date<\/code>: This is the date that you want to subtract a value.<\/li>\n\n\n\n<li>\u00a0<code>expr<\/code>: This is a string that determines an interval value that you want to subtract from the date. The <code>unit<\/code> is the interval unit that <code>expr<\/code> should be interpreted e.g., <code>DAY<\/code>, <code>HOUR<\/code>, etc.<\/li>\n<\/ul>\n\n\n\n<p>The <code>DATE_SUB()<\/code> function returns NULL if the date is NULL. <\/p>\n\n\n\n<p>The following statement uses the\u00a0<code>DATE_SUB()<\/code> function to subtract one day from the <code>July-4th-2017<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">DATE_SUB<\/span>(<span class=\"hljs-string\">'2017-07-04'<\/span>,<span class=\"hljs-built_in\">INTERVAL<\/span> <span class=\"hljs-number\">1<\/span> <span class=\"hljs-keyword\">DAY<\/span>) <span class=\"hljs-keyword\">result<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+------------+\n| result     |\n+------------+\n| <span class=\"hljs-number\">2017<\/span><span class=\"hljs-number\">-07<\/span><span class=\"hljs-number\">-03<\/span> |\n+------------+\n<span class=\"hljs-number\">1<\/span> row <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.00 sec) <\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The date is <code>2017-07-04<\/code>, which is in the <code>yyyy-mm-dd<\/code> format. <\/li>\n\n\n\n<li>The <code>INTERVAL 1 DAY<\/code> is interpreted as 1 day interval. <\/li>\n<\/ul>\n\n\n\n<p>The <code>DATE_SUB()<\/code> function returns a string value that represents the date <code>July, 3rd 2017<\/code><\/p>\n\n\n\n<p>Similar to the <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-date-functions\/mysql-date_add\/\">DATE_ADD()<\/a><\/code> function, the data type of the return value of the <code>DATE_SUB()<\/code> function can be:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>a <code>DATETIME<\/code> value if the first argument is a <code>DATETIME<\/code> or the interval has time elements such as the&nbsp;hour, minute, second, etc.<\/li>\n\n\n\n<li>a string otherwise.<\/li>\n<\/ul>\n\n\n\n<p>See the following example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">DATE_SUB<\/span>(<span class=\"hljs-string\">'2017-07-04'<\/span>,<span class=\"hljs-built_in\">INTERVAL<\/span> <span class=\"hljs-number\">3<\/span> <span class=\"hljs-keyword\">HOUR<\/span>) <span class=\"hljs-keyword\">result<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+---------------------+\n| result              |\n+---------------------+\n| <span class=\"hljs-number\">2017<\/span><span class=\"hljs-number\">-07<\/span><span class=\"hljs-number\">-03<\/span> <span class=\"hljs-number\">21<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span> |\n+---------------------+\n<span class=\"hljs-number\">1<\/span> row <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Because the interval is 3 hours, the result of the <code>DATE_SUB<\/code> function is a <code>DATETIME<\/code> value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Negative interval<\/h2>\n\n\n\n<p>The <code>expr<\/code> in the interval can be positive or negative. In case the <code>expr<\/code> is negative, the <code>DATE_SUB()<\/code> function behaves like the <code>DATE_ADD()<\/code> function as shown in the following example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">DATE_SUB<\/span>(<span class=\"hljs-string\">'2017-07-03'<\/span>,<span class=\"hljs-built_in\">INTERVAL<\/span> <span class=\"hljs-number\">-1<\/span> <span class=\"hljs-keyword\">DAY<\/span>) <span class=\"hljs-keyword\">result<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+------------+\n| result     |\n+------------+\n| <span class=\"hljs-number\">2017<\/span><span class=\"hljs-number\">-07<\/span><span class=\"hljs-number\">-04<\/span> |\n+------------+\n<span class=\"hljs-number\">1<\/span> row <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Invalid or malformed date<\/h2>\n\n\n\n<p>If the first argument of the <code>DATE_SUB()<\/code> function is a malformed, invalid date, or <code>NULL<\/code>, the <code>DATE_SUB()<\/code> function returns <code>NULL<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">DATE_SUB<\/span>(<span class=\"hljs-string\">'2017-02-29'<\/span>, <span class=\"hljs-built_in\">INTERVAL<\/span> - <span class=\"hljs-number\">1<\/span> <span class=\"hljs-keyword\">DAY<\/span>) <span class=\"hljs-keyword\">result<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+--------+\n| result |\n+--------+\n| NULL   |\n+--------+\n<span class=\"hljs-number\">1<\/span> row <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span>, 1 warning (0.00 sec)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, <code>2017-02-03<\/code> is an invalid date, therefore, the result is <code>NULL<\/code>. In addition, MySQL produced a warning.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">SHOW WARNINGS;<\/code><\/span><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+---------+------+----------------------------------------+\r\n| Level   | Code | Message                                |\r\n+---------+------+----------------------------------------+\r\n| Warning | <span class=\"hljs-number\">1292<\/span> | Incorrect datetime value: <span class=\"hljs-string\">'2017-02-29'<\/span> |\r\n+---------+------+----------------------------------------+\r\n<span class=\"hljs-number\">1<\/span> row <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The following examples demonstrate the effects when passing a malformed date or\u00a0<code>NULL<\/code> to the <code>DATE_SUB<\/code> function:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">SELECT DATE_SUB(<span class=\"hljs-string\">'03\/07\/2017'<\/span>, INTERVAL <span class=\"hljs-number\">1<\/span> DAY) result;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">+<span class=\"hljs-comment\">--------+<\/span>\n| result |\n+<span class=\"hljs-comment\">--------+<\/span>\n| NULL   |\n+<span class=\"hljs-comment\">--------+<\/span>\n1 row in <span class=\"hljs-keyword\">set<\/span>, <span class=\"hljs-number\">1<\/span> <span class=\"hljs-keyword\">warning<\/span> (<span class=\"hljs-number\">0.00<\/span> sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">SELECT DATE_SUB(<span class=\"hljs-keyword\">NULL<\/span>, INTERVAL <span class=\"hljs-number\">1<\/span> DAY) result;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+--------+\n| result |\n+--------+\n| NULL   |\n+--------+\n<span class=\"hljs-number\">1<\/span> row <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">MySQL DATE_SUB: automatically adjusted day<\/h2>\n\n\n\n<p>If you subtract <code>MONTH<\/code>, <code>YEAR<\/code>, or <code>YEAR_MONTH<\/code> from a date and the new date has a day that&#8217;s too big for the new month, the <code>DATE_SUB()<\/code> will adjust the day to the latest day of the new month. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">DATE_SUB<\/span>(<span class=\"hljs-string\">'2017-03-30'<\/span>, <span class=\"hljs-built_in\">INTERVAL<\/span> <span class=\"hljs-number\">1<\/span> <span class=\"hljs-keyword\">MONTH<\/span>) <span class=\"hljs-keyword\">result<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+------------+\n| result     |\n+------------+\n| <span class=\"hljs-number\">2017<\/span><span class=\"hljs-number\">-02<\/span><span class=\"hljs-number\">-28<\/span> |\n+------------+\n<span class=\"hljs-number\">1<\/span> row <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, we subtracted 1 month from <code>March 30th 2017<\/code>, therefore, the result is <code>February 28th 2017<\/code>. <\/p>\n\n\n\n<p>However, the <code>DATE_SUB()<\/code> function adjusted the day to 28 instead of 30 because <code>February 2017<\/code> has 28 days only.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the MySQL <code>DATE_SUB()<\/code> function to subtract an interval from a <code>DATE<\/code> or <code>DATETIME<\/code> value.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful? <\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"6170\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-date-functions\/mysql-date_sub\/\"\n\t\t\t\tdata-post-title=\"MySQL DATE_SUB() Function\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"6170\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-date-functions\/mysql-date_sub\/\"\n\t\t\t\tdata-post-title=\"MySQL DATE_SUB() Function\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows you how to use the MySQL DATE_SUB function to subtract an interval from a DATE or DATETIME value.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":7032,"menu_order":9,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-6170","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MySQL DATE_SUB() Function<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to use the MySQL DATE_SUB() function to subtract a time value (or an interval) from a DATE or DATETIME value.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mysqltutorial.org\/mysql-date_sub\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL DATE_SUB() Function\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to use the MySQL DATE_SUB() function to subtract a time value (or an interval) from a DATE or DATETIME value.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-date_sub\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-15T00:51:09+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-date_sub\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-date_sub\\\/\",\"name\":\"MySQL DATE_SUB() Function\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"datePublished\":\"2017-07-08T07:11:58+00:00\",\"dateModified\":\"2023-10-15T00:51:09+00:00\",\"description\":\"This tutorial shows you how to use the MySQL DATE_SUB() function to subtract a time value (or an interval) from a DATE or DATETIME value.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-date_sub\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-date_sub\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-date_sub\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL Date Functions\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-date-functions\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MySQL DATE_SUB() Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\",\"name\":\"MySQL Tutorial\",\"description\":\"A comprehensive MySQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mysqltutorial.org\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MySQL DATE_SUB() Function","description":"This tutorial shows you how to use the MySQL DATE_SUB() function to subtract a time value (or an interval) from a DATE or DATETIME value.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mysqltutorial.org\/mysql-date_sub\/","og_locale":"en_US","og_type":"article","og_title":"MySQL DATE_SUB() Function","og_description":"This tutorial shows you how to use the MySQL DATE_SUB() function to subtract a time value (or an interval) from a DATE or DATETIME value.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-date_sub\/","og_site_name":"MySQL Tutorial","article_modified_time":"2023-10-15T00:51:09+00:00","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-date_sub\/","url":"https:\/\/www.mysqltutorial.org\/mysql-date_sub\/","name":"MySQL DATE_SUB() Function","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"datePublished":"2017-07-08T07:11:58+00:00","dateModified":"2023-10-15T00:51:09+00:00","description":"This tutorial shows you how to use the MySQL DATE_SUB() function to subtract a time value (or an interval) from a DATE or DATETIME value.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-date_sub\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-date_sub\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-date_sub\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL Date Functions","item":"https:\/\/www.mysqltutorial.org\/mysql-date-functions\/"},{"@type":"ListItem","position":3,"name":"MySQL DATE_SUB() Function"}]},{"@type":"WebSite","@id":"https:\/\/www.mysqltutorial.org\/#website","url":"https:\/\/www.mysqltutorial.org\/","name":"MySQL Tutorial","description":"A comprehensive MySQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mysqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/6170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/comments?post=6170"}],"version-history":[{"count":3,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/6170\/revisions"}],"predecessor-version":[{"id":11188,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/6170\/revisions\/11188"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/7032"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=6170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}