The above query will return last 10 days records. Last 10 days records select * from dt_table where `date` >= DATE_SUB(CURDATE(), INTERVAL 10 DAY) Here are some sample queries on how to get the records as per requirements. To get the difference in today date and previous day or month we have to use the MySQL function DATE_SUBĭATE_SUB is a MySQL function which takes date expression, the interval and the constant to return the date value for further calculation. We will use the MySQL function CURDATE() to get the today's date. Here irrespective of the date values we want the records of last X days from today, or we can say that the records between today and last X days ( month, year or week) are required. What are the books arrived in last one year. One shop may be interested in knowing new products added in last one month. SELECT MIN(date),MAX(date) FROM dt_table įor example let us find out who are the new members joined in our forum in last week. Use this query to get the distribution of date from both sides of today's date. You may not get any record when searching for last 10 days record by using SQL dump of more than 10 days old.
0 Comments
Leave a Reply. |