MySQL Interval

Rate this post
  • MySQL interval values are used mainly for date and time calculations.

INTERVAL {value of unit} {types of interval}

  • INTERVAL is a MySQL keyword and this is case sensitive. This should be used in CAPITAL Later Only
  • {value of unit} is a expression or value like 1,2,3,4 or any expression which result in value.
  • {type of interval} is a MySQL date time unit and is described below. This show also be used in CAPITAL later only.

Type of Interval

mysql interval
mysql interval

Examples:

Query:

SELECT ‘2018-03-23’ + INTERVAL 1 DAY;

Result:

+——————————-+
| 201803-24                    |
+————————
Query:
SELECT ‘2018-03-23’ + INTERVAL -1 DAY;
+——————————–+
| 2018-03-22                     |
+——————————–+

Related Posts

  • 69
    Very often we need to extract last 30 days, 7 days data from mysql DB. Here we will show easy way to get the data of given interval. SELECT DATE_FORMAT(create_date, '%m/%d/%Y') FROM mytable WHERE create_date BETWEEN CURDATE() - INTERVAL 30 DAY AND CURDATE() Also note that CURDATE() returns only the DATE…
    Tags: interval, select, mysql, day, query, time
  • 55
    Very often we need to extract last 1 month, 2 months data from mysql DB. Here we will show easy way to get the data of given interval. SELECT * from testtable WHERE startdate BETWEEN DATE_SUB(NOW(), INTERVAL 1 MONTH) AND DATE_SUB(NOW(), INTERVAL 2 MONTH) The above query will return records whose order…
    Tags: interval, mysql, query, select
  • 46
    The core logic of a database application is performed through SQL statements, whether issued directly through an interpreter or submitted behind the scenes through an API. The tuning guidelines of this post will help to speed up all kinds of MySQL applications. The guidelines cover SQL operations that read and…
    Tags: query, select, mysql, time
  • 39
    Syntax: IF(expr,if_true_expr,if_false_expr) MySQL IF function is control flow functions that returns a value based on a condition. The IF function is sometimes referred to as IF ELSE or IF THEN ELSE function. If the expr evaluates to TRUE i.e., expr is not NULL and expr is not 0, the IF…
    Tags: select, mysql
  • 37
    I connect to mysql from my Linux shell. Every now and then I run a SELECT query that is too big. It prints and prints and I already know this is not what I meant. I would like to stop the query. Hitting Ctrl+C (a couple of times) kills mysql…
    Tags: mysql, query, select

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: