Skip to content
Advertisement

Select current week, starts from Monday instead of Sunday

I’ve managed to select the data from the current week but the week itself starts from Sunday which is not the right format for me, it should starts from Monday. I’m using MySQL to query the data.

Advertisement

Answer

You can use this little formula to get the Monday starting the week of any given DATE, DATETIME, or TIMESTAMP object.

I like to use it in a stored function named TRUNC_MONDAY(datestamp) defined like this.

Then you can do stuff like this

or even this to get a report covering eight previous weeks and the current week.

I particularly like this TRUNC_MONDAY() approach because it works unambiguously even for calendar weeks that contain New Years’ Days.

(If you want TRUNC_SUNDAY() change the -2 in the formula to -1.)

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement