I want to write a function which will take today’s date and reply me the number of weekdays only. For e.g. today is 04-28-2013. Result should be 20. How ?? today’s date minus 8 days as weekend passed. If today’s date is 0-17-2013 then result should be 12.

Catch is to know how many weekends are passed from today’s date. I need to calculate dynamic everyday.

To me, that code is *far* too dependent on specific date and language settings, aside from having extra overhead. How about instead:
SELECT DATEDIFF(DAY, 0, A.ModifiedDate) % 7 <= 4 THEN 'Weekday' ELSE 'Weekend' END
That code has *NO* reliance on date or language settings to determine the correct result.

hi, can anyone tell me how to filter datetime column based on current date, weekly and monthly.
Select * from timeattendance where clmdatetime = GETDATE() <== that is for datetime now, but I want the date without the time.
How about filter weekly (monday to sunday) and monthly (ist of month and end of month)?

Hi,
My Table have week_end_date(Friday) and days of week as column, but you know some time weeks overlap in two months that causing wrong month wise report. Any suggestion how to consolidate data coreectly month wise.

Community Initiatives

About Pinal Dave

Pinal Dave is a Pluralsight Developer Evangelist. He has authored 11 SQL Server database books, 17 Pluralsight courses and have written over 3200 articles on the database technology on his blog at a http://blog.sqlauthority.com. Along with 11+ years of hands on experience he holds a Masters of Science degree and a number of certifications, including MCTS, MCDBA and MCAD (.NET). His past work experiences include Technology Evangelist at Microsoft and Sr. Consultant at SolidQ. Follow @pinaldave
Send Author Pinal Dave
an email at pinal@sqlauthority.com

Email Subscription

Enter your email address to subscribe to this blog and receive notifications of new posts by email.