I\'m building a weekly report using MySQL queries. First I get week number by
SELECT WEEK(CURDATE());
Then I need to displ
SELECT DATE_ADD((SELECT curdate() - INTERVAL (WEEKDAY(curdate())+1)DAY),INTERVAL 1 DAY) as current_monday
For thhose who need the Monday date of the current week.
If you count Monday as the first day of the week:
SELECT STR_TO_DATE(CONCAT(YEARWEEK(NOW(), 1),'Monday'), '%x%v %W');
If you count Sunday as the first day of the week:
SELECT STR_TO_DATE(CONCAT(YEARWEEK(NOW()),'Monday'), '%X%V %W');
You can use this:
<?php
$week = date('W');
$year = date('Y');
echo $date1 = date(
'Y-m-d',
strtotime($year . 'W' . str_pad($week, 2, '0', STR_PAD_LEFT))
);
?>
If you need date of monday in current week try this:
SELECT DATE_ADD(CURDATE(), INTERVAL - WEEKDAY(CURDATE()) DAY)
It return you monday date of current week.
In fact, we substruct days, not add them. Just more simple expression:
DATE_SUB( CURDATE(), INTERVAL WEEKDAY( CURDATE() )
-- current week monday
(SELECT DATE_ADD(CURDATE(), INTERVAL - WEEKDAY(CURDATE()) DAY))
-- current week friday
SELECT DATE_ADD((SELECT DATE_ADD(CURDATE(), INTERVAL - WEEKDAY(CURDATE()) DAY)),INTERVAL 4 DAY);
-- next week monday
SELECT date(curdate() - interval weekday(curdate()) day + interval 1 week);
-- next week friday
SELECT DATE_ADD((SELECT date(curdate() - interval weekday(curdate()) day + interval 1 week)),INTERVAL 4 DAY);