Get last 30 day records from today date in SQL

Jyotishgher Astrology
By -
0

 Get last 30 day records from today date in SQL 


This query will show  30days Record only

SELECT a.*,b.* from  olx.sp_item a,olx.sp_item_photo b where a.ITEMID=b.ITEMID and a.ITEM_CATEGORY='Appliance' and a.ACTIVE_FLAG='Y' and add_months(a.ENTER_DT,1)>SYSDATE;



This query will show  2days Record only


SELECT a.*,b.* from  olx.sp_item a,olx.sp_item_photo b where a.ITEMID=b.ITEMID and a.ITEM_CATEGORY='Appliance' and a.ACTIVE_FLAG='Y' and (a.ENTER_DT+2)>SYSDATE;


You can use DateDiff for this. The where clause in your query would look like:

where DATEDIFF(day,pdate,GETDATE()) < 31

5

Below query is appropriate for the last 30 days records

Here, I have used a review table and review_date is a column from the review table

SELECT * FROM reviews WHERE DATE(review_date) >= DATE(NOW()) - INTERVAL 30 DAY


You can use this to get the data of the last 30 days, based on a column.

WHERE DATEDIFF(dateColumn, CURRENT_TIMESTAMP) BETWEEN 0 AND 30

Post a Comment

0Comments

Post a Comment (0)