DAYOFWEEK(date)
Example
SELECT DAYOFWEEK('2016-05-06')# Output is 6
1 = Sunday , 2 = Monday, 3 = Tuesday, 4 = Wednesday , 5 = Thursday, 6 = Friday, 7 = Saturday
SELECT id,date,weekday, dayofweek(date) as dayofweek
FROM dt_weekday
WHERE `date` BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL (dayofweek(CURDATE())-2) DAY ) AND CURDATE( )
Above query will collect records starting from Monday and ending with today. For example if today is Tuesday then you will get two records ( of Monday and Tuesday ) SELECT DATE_SUB( CURDATE( ) ,INTERVAL (dayofweek(CURDATE())-2) DAY )
Please 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.
Monday = 0, Tuesday = 1 and so on ...
Here is a simple query
SELECT WEEKDAY( '2014-08-15' )
Output of above query is 4 . (15th Aug 2014 is Friday).
SELECT id, DATE, weekday, WEEKDAY( CURDATE( ) ) AS weekday
FROM dt_weekday
WHERE `date` BETWEEN DATE_SUB( CURDATE( ) , INTERVAL( WEEKDAY( CURDATE( ) ) ) DAY ) AND CURDATE( )
SELECT id, DATE, weekday, DAYOFWEEK( CURDATE( ) ) AS dayofweek
FROM dt_weekday
WHERE `date`
BETWEEN DATE_SUB( CURDATE( ) , INTERVAL (dayofweek(CURDATE())+5)
DAY )
AND DATE_SUB( CURDATE( ) , INTERVAL (dayofweek(CURDATE()))
DAY )
SELECT id, DATE, weekday, DAYOFWEEK( CURDATE( ) ) AS dayofweek
FROM dt_weekday
WHERE `date`
BETWEEN DATE_SUB( CURDATE( ) , INTERVAL( DAYOFWEEK( CURDATE( ) ) +12 )
DAY )
AND DATE_SUB( CURDATE( ) , INTERVAL( DAYOFWEEK( CURDATE( ) ) +7 )
DAY )
CREATE TABLE IF NOT EXISTS `dt_weekday` (
`id` varchar(3) NOT NULL,
`date` date NOT NULL,
`weekday` varchar(3) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `dt_weekday` VALUES ('-15', '2025-12-15','Mon' );
INSERT INTO `dt_weekday` VALUES ('-14', '2025-12-14','Sun' );
INSERT INTO `dt_weekday` VALUES ('-13', '2025-12-13','Sat' );
INSERT INTO `dt_weekday` VALUES ('-12', '2025-12-12','Fri' );
INSERT INTO `dt_weekday` VALUES ('-11', '2025-12-11','Thu' );
INSERT INTO `dt_weekday` VALUES ('-10', '2025-12-10','Wed' );
INSERT INTO `dt_weekday` VALUES ('-9', '2025-12-09','Tue' );
INSERT INTO `dt_weekday` VALUES ('-8', '2025-12-08','Mon' );
INSERT INTO `dt_weekday` VALUES ('-7', '2025-12-07','Sun' );
INSERT INTO `dt_weekday` VALUES ('-6', '2025-12-06','Sat' );
INSERT INTO `dt_weekday` VALUES ('-5', '2025-12-05','Fri' );
INSERT INTO `dt_weekday` VALUES ('-4', '2025-12-04','Thu' );
INSERT INTO `dt_weekday` VALUES ('-3', '2025-12-03','Wed' );
INSERT INTO `dt_weekday` VALUES ('-2', '2025-12-02','Tue' );
INSERT INTO `dt_weekday` VALUES ('-1', '2025-12-01','Mon' );
INSERT INTO `dt_weekday` VALUES ('0', '2025-11-30','Sun' );
INSERT INTO `dt_weekday` VALUES ('1', '2025-11-29','Sat' );
INSERT INTO `dt_weekday` VALUES ('2', '2025-11-28','Fri' );
INSERT INTO `dt_weekday` VALUES ('3', '2025-11-27','Thu' );
INSERT INTO `dt_weekday` VALUES ('4', '2025-11-26','Wed' );
INSERT INTO `dt_weekday` VALUES ('5', '2025-11-25','Tue' );
INSERT INTO `dt_weekday` VALUES ('6', '2025-11-24','Mon' );
INSERT INTO `dt_weekday` VALUES ('7', '2025-11-23','Sun' );
INSERT INTO `dt_weekday` VALUES ('8', '2025-11-22','Sat' );
INSERT INTO `dt_weekday` VALUES ('9', '2025-11-21','Fri' );
INSERT INTO `dt_weekday` VALUES ('10', '2025-11-20','Thu' );
INSERT INTO `dt_weekday` VALUES ('11', '2025-11-19','Wed' );
INSERT INTO `dt_weekday` VALUES ('12', '2025-11-18','Tue' );
INSERT INTO `dt_weekday` VALUES ('13', '2025-11-17','Mon' );
INSERT INTO `dt_weekday` VALUES ('14', '2025-11-16','Sun' );
INSERT INTO `dt_weekday` VALUES ('15', '2025-11-15','Sat' );
INSERT INTO `dt_weekday` VALUES ('16', '2025-11-14','Fri' );
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.