How do I get the first day of a given week whose week number is available?
For example as I write this post we are at WEEK 29.I would like to write a MySQL query that will return Sunday 18 July using this WEEKNO 29 as the only available parameter.
WEEK() function in MySQL is used to find week number for a given date. If the date is NULL, the WEEK() function will return NULL. Otherwise, it returns the value of week which ranges between 0 to 53. The date or datetime from which we want to extract the week.
MySQL WEEK() Function The WEEK() function returns the week number for a given date (a number from 0 to 53).
The DATE_ADD() function adds a time/date interval to a date and then returns the date.
This is an accurate way of getting the first day of the week and the last day of the week based on the current date:
adddate(curdate(), INTERVAL 1-DAYOFWEEK(curdate()) DAY) WeekStart, adddate(curdate(), INTERVAL 7-DAYOFWEEK(curdate()) DAY) WeekEnd
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With