SQL PHP HTML ASP JavaScript articles and free scripts to download

Records of the weekdays

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. 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.

Google+

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer