How to make a query per day, week, month period in Mysql

Asked

Viewed 1,636 times

1

How do I query for period, day, week, month in Mysql? for example I would like to display data filtered by periods example display data yesterday, last week, two weeks, three weeks, a month ago and so on date in date format 2017-06-21 09:26:31

1 answer

3


There are many ways to do this, see the Mysql documentation for Dates:MYSQL Date and Time Functions.

Examples:

Yesterday:

Select * minhaTabela where Date(Data) = DATE_SUB(CURDATE(),INTERVAL 1 DAY);

or

Select * minhaTabela where Date(DATE_ADD(Data,INTERVAL 1 DAY)) = CURDATE();

Last week:

Select * from minhaTabela where Week(data)+1 = Week(curdate());

...The documentation has several functions and examples.

  • 1

    Thank you, it worked perfectly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.