mysql query get date of 1 month interval

Rate this post

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 date is between one and two months.

Related Posts

  • 61
    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, data, will, query, records, easy, db, extract
  • 55
    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…
    Tags: interval, mysql, select, query
  • 47
    A Shell script for killing slow MySQL queries: #!/bin/sh # Credentials for a MySQL user with PROCESS, SUPER permissions USERNAME= PASSWORD= # MySQL Server location HOST= PORT=3306 TIMEOUT=60 # 1 minute TARGET_USER= # MySQL user to monitor MYSQL="mysql -u $USERNAME --password=$PASSWORD -h $HOST -P $PORT -B" $MYSQL -N -e 'SHOW…
    Tags: mysql, learn, query
  • 47
    What is database? Database is an organized collection of information about an entity having controlled redundancy and serves multiple applications. DBMS (database management system) is an application software that is developed to create and manipulate the data in database. A query language can easily access a data in a database.…
    Tags: data, query, mysql, db
  • 43
    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: