How to get last 1 hour to last 10 days data in mysql?

Member

by dana , in category: MySQL , 6 months ago

How to get last 1 hour to last 10 days data in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lottie , 6 months ago

@dana 

To get the data from the last 1 hour to the last 10 days in MySQL, you can use the BETWEEN operator with DATE_SUB and NOW functions. Here is an example query:

1
2
3
SELECT *
FROM your_table
WHERE your_datetime_column BETWEEN DATE_SUB(NOW(), INTERVAL 10 DAY) AND DATE_SUB(NOW(), INTERVAL 1 HOUR);


Replace your_table with the name of your table and your_datetime_column with the name of your datetime column.


This query will retrieve all records from the specified table where the datetime column falls within the range of the last 10 days to the last 1 hour.