{"id":6049,"date":"2017-07-06T02:07:53","date_gmt":"2017-07-06T09:07:53","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=6049"},"modified":"2023-12-31T02:58:53","modified_gmt":"2023-12-31T09:58:53","slug":"mysql-interval","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-interval\/","title":{"rendered":"MySQL Interval"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use MySQL interval values to perform date and time arithmetic.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to MySQL interval values<\/h2>\n\n\n\n<p>MySQL interval values are used mainly for <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-date\/\">date <\/a>and <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-time\/\">time<\/a> calculations. To create an interval value, you use the following expression:<\/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\">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>Followed by the <code>INTERVAL<\/code> keyword is the <code>expr<\/code> that determines the interval value, and <code>unit<\/code> that specifies the interval unit. For example, to create a 1-day interval, you use the following expression:<\/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\">INTERVAL 1 DAY<\/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>Notice that the <code>INTERVAL<\/code> and <code>UNIT<\/code> are case-insensitive therefore the following expression is equivalent to the one above:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">interval 1 day<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><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>We mainly use interval values for date and time arithmetic as shown below:<\/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\">date + INTERVAL expr unit\ndate - INTERVAL expr unit<\/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>The interval values are also used in various temporal functions such as <a href=\"https:\/\/www.mysqltutorial.org\/mysql-date-functions\/mysql-date_add\/\"><code>DATE_ADD,<\/code><\/a><a href=\"https:\/\/www.mysqltutorial.org\/mysql-date-functions\/mysql-date_sub\/\"><code>DATE_SUB<\/code><\/a>, <code>TIMESTAMPADD<\/code> and <code>TIMESTAMPDIFF<\/code>.<\/p>\n\n\n\n<p>MySQL defines standard formats for <code>expr<\/code> and <code>unit<\/code> as illustrated in the following table:<\/p>\n\n\n\n<figure class=\"wp-block-table ref\"><table><thead><tr><th><strong>unit<\/strong><strong>&nbsp;<\/strong><\/th><th><strong>expr<\/strong><strong>&nbsp;<\/strong><\/th><\/tr><\/thead><tbody><tr><td>DAY<\/td><td>DAYS<\/td><\/tr><tr><td>DAY_HOUR<\/td><td>&#8216;DAYS HOURS&#8217;<\/td><\/tr><tr><td>DAY_MICROSECOND<\/td><td>&#8216;DAYS HOURS:MINUTES:SECONDS.MICROSECONDS&#8217;<\/td><\/tr><tr><td>DAY_MINUTE<\/td><td>&#8216;DAYS HOURS:MINUTES&#8217;<\/td><\/tr><tr><td>DAY_SECOND<\/td><td>&#8216;DAYS HOURS:MINUTES:SECONDS&#8217;<\/td><\/tr><tr><td>HOUR<\/td><td>HOURS<\/td><\/tr><tr><td>HOUR_MICROSECOND<\/td><td>&#8216;HOURS:MINUTES:SECONDS.MICROSECONDS&#8217;<\/td><\/tr><tr><td>HOUR_MINUTE<\/td><td>&#8216;HOURS:MINUTES&#8217;<\/td><\/tr><tr><td>HOUR_SECOND<\/td><td>&#8216;HOURS:MINUTES:SECONDS&#8217;<\/td><\/tr><tr><td>MICROSECOND<\/td><td>MICROSECONDS<\/td><\/tr><tr><td>MINUTE<\/td><td>MINUTES<\/td><\/tr><tr><td>MINUTE_MICROSECOND<\/td><td>&#8216;MINUTES:SECONDS.MICROSECONDS&#8217;<\/td><\/tr><tr><td>MINUTE_SECOND<\/td><td>&#8216;MINUTES:SECONDS&#8217;<\/td><\/tr><tr><td>MONTH<\/td><td>MONTHS<\/td><\/tr><tr><td>QUARTER<\/td><td>QUARTERS<\/td><\/tr><tr><td>SECOND<\/td><td>SECONDS<\/td><\/tr><tr><td>SECOND_MICROSECOND<\/td><td>&#8216;SECONDS.MICROSECONDS&#8217;<\/td><\/tr><tr><td>WEEK<\/td><td>WEEKS<\/td><\/tr><tr><td>YEAR<\/td><td>YEARS<\/td><\/tr><tr><td>YEAR_MONTH<\/td><td>&#8216;YEARS-MONTHS&#8217;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL interval examples<\/h2>\n\n\n\n<p>The following statement adds 1 day to <code>January 1st 2020<\/code> that returns <code>January 2nd 2020<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" 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-string\">'2020-01-01'<\/span> + <span class=\"hljs-built_in\">INTERVAL<\/span> <span class=\"hljs-number\">1<\/span> <span class=\"hljs-keyword\">DAY<\/span>;\n+<span class=\"hljs-comment\">-------------------------------+<\/span>\n| '2020-01-01' + INTERVAL 1 DAY |\n+<span class=\"hljs-comment\">-------------------------------+<\/span>\n| 2020-01-02                    |\n+<span class=\"hljs-comment\">-------------------------------+<\/span>\n1 row in <span class=\"hljs-keyword\">set<\/span> (<span class=\"hljs-number\">0.01<\/span> sec)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><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>If an interval value is used in an expression that involves a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-date\/\"><code>DATE<\/code><\/a> or <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-datetime\/\">DATETIME<\/a><\/code> value and the interval value is on the right side of the expression, you can use the negative value of the \u00a0<code>expr<\/code> 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-string\">'2020-01-01'<\/span> + <span class=\"hljs-built_in\">INTERVAL<\/span> <span class=\"hljs-number\">-1<\/span> <span class=\"hljs-keyword\">DAY<\/span>;\n+<span class=\"hljs-comment\">--------------------------------+<\/span>\n| '2020-01-01' + INTERVAL -1 DAY |\n+<span class=\"hljs-comment\">--------------------------------+<\/span>\n| 2019-12-31                     |\n+<span class=\"hljs-comment\">--------------------------------+<\/span>\n1 row in <span class=\"hljs-keyword\">set<\/span> (<span class=\"hljs-number\">0.00<\/span> sec) \n<\/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>The following statement shows how to use <a href=\"https:\/\/www.mysqltutorial.org\/mysql-date-functions\/mysql-date_add\/\"><code>DATE_ADD<\/code><\/a> and <a href=\"https:\/\/www.mysqltutorial.org\/mysql-date-functions\/mysql-date_sub\/\"><code>DATE_SUB<\/code><\/a> to add\/subtract 1 month to\/from a date value:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" 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_ADD<\/span>(<span class=\"hljs-string\">'2020-01-01'<\/span>, <span class=\"hljs-built_in\">INTERVAL<\/span> <span class=\"hljs-number\">1<\/span> <span class=\"hljs-keyword\">MONTH<\/span>) <span class=\"hljs-number\">1<\/span>_MONTH_LATER, \n       <span class=\"hljs-keyword\">DATE_SUB<\/span>(<span class=\"hljs-string\">'2020-01-01'<\/span>,<span class=\"hljs-built_in\">INTERVAL<\/span> <span class=\"hljs-number\">1<\/span> <span class=\"hljs-keyword\">MONTH<\/span>) <span class=\"hljs-number\">1<\/span>_MONTH_BEFORE;\n+<span class=\"hljs-comment\">---------------+----------------+<\/span>\n| 1_MONTH_LATER | 1_MONTH_BEFORE |\n+<span class=\"hljs-comment\">---------------+----------------+<\/span>\n| 2020-02-01    | 2019-12-01     |\n+<span class=\"hljs-comment\">---------------+----------------+<\/span>\n1 row in <span class=\"hljs-keyword\">set<\/span> (<span class=\"hljs-number\">0.00<\/span> sec)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><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 following query uses <code>TIMESTAMPADD(unit,interval,expression)<\/code> function to add 30 minutes to a timestamp value:<\/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\">TIMESTAMPADD<\/span>(<span class=\"hljs-keyword\">MINUTE<\/span>,<span class=\"hljs-number\">30<\/span>,<span class=\"hljs-string\">'2020-01-01'<\/span>) <span class=\"hljs-number\">30<\/span>_MINUTES_LATER;\n+<span class=\"hljs-comment\">---------------------+<\/span>\n| 30_MINUTES_LATER    |\n+<span class=\"hljs-comment\">---------------------+<\/span>\n| 2020-01-01 00:30:00 |\n+<span class=\"hljs-comment\">---------------------+<\/span>\n1 row in <span class=\"hljs-keyword\">set<\/span> (<span class=\"hljs-number\">0.00<\/span> sec)\n<\/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<h3 class=\"wp-block-heading\">MySQL interval practical example<\/h3>\n\n\n\n<p>Let&#8217;s<a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-create-table\/\"> create a new table<\/a> called <code>memberships<\/code> for demonstration:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> memberships (\n    <span class=\"hljs-keyword\">id<\/span> <span class=\"hljs-built_in\">INT<\/span> AUTO_INCREMENT PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n    email <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">355<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    plan <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">255<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    expired_date <span class=\"hljs-built_in\">DATE<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>\n);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><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>In the <code>memberships<\/code> table, the <code>expired_date<\/code> column stores the membership&#8217;s expiration date for each member.<\/p>\n\n\n\n<p>The following statement <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-insert\/\">inserts<\/a> some rows into the <code>memberships<\/code> table.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> memberships(email, plan, expired_date)\n<span class=\"hljs-keyword\">VALUES<\/span>(<span class=\"hljs-string\">'john.doe@example.com'<\/span>,<span class=\"hljs-string\">'Gold'<\/span>,<span class=\"hljs-string\">'2017-07-13'<\/span>),\n      (<span class=\"hljs-string\">'jane.smith@example.com'<\/span>,<span class=\"hljs-string\">'Platinum'<\/span>,<span class=\"hljs-string\">'2017-07-10'<\/span>),\n      (<span class=\"hljs-string\">'david.corp@example.com'<\/span>,<span class=\"hljs-string\">'Silver'<\/span>,<span class=\"hljs-string\">'2017-07-15'<\/span>),\n      (<span class=\"hljs-string\">'julia.william@example.com'<\/span>,<span class=\"hljs-string\">'Gold'<\/span>,<span class=\"hljs-string\">'2017-07-20'<\/span>),\n      (<span class=\"hljs-string\">'peter.drucker@example.com'<\/span>,<span class=\"hljs-string\">'Silver'<\/span>,<span class=\"hljs-string\">'2017-07-08'<\/span>);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><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>Suppose today is <code>2017-07-06<\/code>, you can find the members whose memberships expired within 7 days using the following query:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" 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> \n    email,\n    plan,\n    expired_date,\n    <span class=\"hljs-keyword\">DATEDIFF<\/span>(expired_date, <span class=\"hljs-string\">'2017-07-06'<\/span>) remaining_days\n<span class=\"hljs-keyword\">FROM<\/span>\n    memberships\n<span class=\"hljs-keyword\">WHERE<\/span>\n    <span class=\"hljs-string\">'2017-07-06'<\/span> <span class=\"hljs-keyword\">BETWEEN<\/span> <span class=\"hljs-keyword\">DATE_SUB<\/span>(expired_date, <span class=\"hljs-built_in\">INTERVAL<\/span> <span class=\"hljs-number\">7<\/span> <span class=\"hljs-keyword\">DAY<\/span>) <span class=\"hljs-keyword\">AND<\/span> expired_date;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><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<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"411\" height=\"79\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Interval-Example.png\" alt=\"MySQL Interval Example\" class=\"wp-image-6052\" title=\"MySQL Interval Example\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Interval-Example.png 411w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Interval-Example-300x58.png 300w\" sizes=\"auto, (max-width: 411px) 100vw, 411px\" \/><\/figure>\n\n\n\n<p>In this query, we used the <code>DATE_SUB<\/code> function to subtract the expired date by 7 days specified by an interval value (<code>INTERVAL 7 DAY<\/code>).<\/p>\n\n\n\n<p>In this tutorial, you have learned how to use MySQL interval value for the date and time arithmetic.<\/p>\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=\"6049\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-interval\/\"\n\t\t\t\tdata-post-title=\"MySQL Interval\"\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=\"6049\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-interval\/\"\n\t\t\t\tdata-post-title=\"MySQL Interval\"\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 step by step how to use the MySQL interval for date and time arithmetic with many practical examples.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":174,"menu_order":102,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-6049","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>An Introduction To MySQL Interval<\/title>\n<meta name=\"description\" content=\"This tutorial shows you step by step how to use the MySQL interval for date and time arithmetic with many practical examples.\" \/>\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-basics\/mysql-interval\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"An Introduction To MySQL Interval\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you step by step how to use the MySQL interval for date and time arithmetic with many practical examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-interval\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-31T09:58:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Interval-Example.png\" \/>\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-basics\\\/mysql-interval\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-interval\\\/\",\"name\":\"An Introduction To MySQL Interval\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-interval\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-interval\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2017\\\/07\\\/MySQL-Interval-Example.png\",\"datePublished\":\"2017-07-06T09:07:53+00:00\",\"dateModified\":\"2023-12-31T09:58:53+00:00\",\"description\":\"This tutorial shows you step by step how to use the MySQL interval for date and time arithmetic with many practical examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-interval\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-interval\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-interval\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2017\\\/07\\\/MySQL-Interval-Example.png\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2017\\\/07\\\/MySQL-Interval-Example.png\",\"width\":411,\"height\":79,\"caption\":\"MySQL Interval Example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-interval\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL Basics\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MySQL Interval\"}]},{\"@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":"An Introduction To MySQL Interval","description":"This tutorial shows you step by step how to use the MySQL interval for date and time arithmetic with many practical examples.","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-basics\/mysql-interval\/","og_locale":"en_US","og_type":"article","og_title":"An Introduction To MySQL Interval","og_description":"This tutorial shows you step by step how to use the MySQL interval for date and time arithmetic with many practical examples.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-interval\/","og_site_name":"MySQL Tutorial","article_modified_time":"2023-12-31T09:58:53+00:00","og_image":[{"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Interval-Example.png","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-interval\/","url":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-interval\/","name":"An Introduction To MySQL Interval","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-interval\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-interval\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Interval-Example.png","datePublished":"2017-07-06T09:07:53+00:00","dateModified":"2023-12-31T09:58:53+00:00","description":"This tutorial shows you step by step how to use the MySQL interval for date and time arithmetic with many practical examples.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-interval\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-interval\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-interval\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Interval-Example.png","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Interval-Example.png","width":411,"height":79,"caption":"MySQL Interval Example"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-interval\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL Basics","item":"https:\/\/www.mysqltutorial.org\/mysql-basics\/"},{"@type":"ListItem","position":3,"name":"MySQL Interval"}]},{"@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\/6049","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=6049"}],"version-history":[{"count":2,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/6049\/revisions"}],"predecessor-version":[{"id":13943,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/6049\/revisions\/13943"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/174"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=6049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}