Query for Today, Yesterday, Week, Month

Discussion of open issues, suggestions and bugs regarding database management and administration tools for MySQL
Post Reply
DenisCGN
Posts: 3
Joined: Fri 10 May 2013 06:16

Query for Today, Yesterday, Week, Month

Post by DenisCGN » Fri 10 May 2013 06:25

Hello,
I need some help. I am not so familiar with MySQL, so I bought Query Builder :-)
I need to have the following recordsets.

New Bands:
Today (only today)
Yesterday (without today)
Week (today till start of the week(monday))
Month (today till start of the current month)

I got the following field in my table to sort. onlineDate "yyyy-mm-dd 00:00:00" (datetime).

My wish will be, to have the exact week (starts on monday). So if today is wednesday it will only go back to monday of the current week. Same for month. from today back to the first day of the current month.

How does that work?

Cheers,
Denis

DenisCGN
Posts: 3
Joined: Fri 10 May 2013 06:16

Re: Query for Today, Yesterday, Week, Month

Post by DenisCGN » Fri 10 May 2013 13:39

So I got the querys for

Today
SELECT * FROM artists WHERE DATE(artists.onlineDate) = CURDATE()

Current Week
SELECT * FROM artists WHERE WEEK(artists.onlineDate, 3) = WEEK(CURDATE(), 3)

Current Month
SELECT * FROM artists WHERE MONTH(artists.onlineDate) = MONTH(CURDATE())

Current Year
SELECT * FROM artists WHERE YEAR(artists.onlineDate) = YEAR(CURDATE())

But I need
Last Week, Last Month, Last Year

Any suggestions?

alexa

Re: Query for Today, Yesterday, Week, Month

Post by alexa » Mon 13 May 2013 14:00

Since the issue goes beyond the scope of our product, we suggest you to search for the answer in some other sources as we provide technical support only on our products.

Post Reply