Search code examples
mysqldrupal-7

Mysql query to check nodes created in last 3 month


I want to query table node in which I want to check records created in last 3 Months. created is my field in table whose data type is timestamp I tried this

SELECT *
FROM node
WHERE created >= DATE_FORMAT(CURDATE(), '%Y-%m-01') INTERVAL -3 MONTH

And also this

SELECT Count(*),DATE_ADD((DATE_FORMAT(FROM_UNIXTIME(created), '%e %b %Y')),INTERVAL -3 MONTH) AS DATERANGE
FROM node

But both are not working


Solution

  • The following is the simplest method I do date operations:

    SELECT *
    FROM node
    WHERE created >= NOW() - INTERVAL 3 MONTH;