How to calculate number of weeks worked by an employee for a fiscal year in sql server

Maddi, Shyam 0 Reputation points
2024-02-02T20:23:26.1633333+00:00

How to determine the total weeks an employee has worked during a fiscal year using SQL Server. My start date is 12-28-2023 and till today, I would like to calculate the no.of weeks worked by an employee during that time.

SQL Server | SQL Server Transact-SQL
Developer technologies | Transact-SQL
SQL Server | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,326 Reputation points
    2024-02-02T21:28:18.2466667+00:00

    Have you tried using DATEDIFF?

    DECLARE @start DATETIME, @end DATETIME
    SET @start = '12/28/2023'
    SET @end = '12/27/2024'
    
    SELECT DATEDIFF(week, @start, @end)
    

    A caveat here is that weeks worked isn't well defined. This is the # of weeks between 2 dates but might not line up with what you consider to be work weeks. For example it doesn't take into account holidays or weekends. If you need that then the calculation will get a lot more complicated as weekends need to be removed and holidays are not a fixed list.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.