K
K
kiri42010-09-26 23:11:17
MySQL
kiri4, 2010-09-26 23:11:17

MySQL how to get start and end of last week given date from day of next (last) week?

I found the solution :)
we have a datetime `time` field in which a certain date is stored, and so the solution:
select TIMESTAMPADD(DAY,-WEEKDAY(`time`)-7,DATE(`time`)) as `WeekStart`,TIMESTAMPADD(DAY,6-WEEKDAY(`time`)-7,DATE(`time`)) as `WeekEnd` from ..
at the output we get WeekStart and WeekEnd with the beginning and end of the week,
"-7" respectively to get the previous one

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question