| | |
Records of the weekdaysPlease read the tutorial on last x day's record in part 1 of this tutorial. Here we will develop a query to get records of weekdays of the present week. To get the records we will try by using dayofweek function of MySQL.
This function dayofweek returns values 1 to 7 based on the weekday starting from Sunday as 1, Monday as 2 and …so on for others. So if today is Thursday then dayofweek function will return 5. So we need before three days record ( excluding today ) from today to get the records stating from Monday. So we will deduct 2 from the weekday figure. Here is the query to get the records of all weekdays of a week till today.
SELECT dt,id,dayofweek(CURDATE()) as c FROM dt_tb WHERE `dt` BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL (dayofweek(CURDATE())-2) DAY ) AND CURDATE( )
We have used the same table as sql dump shown in previous section.
| |
|
|
|
|
|