SQL Server Performance

How to get number of week in a month

Discussion in 'General Developer Questions' started by rudi.anto, Apr 6, 2009.

  1. rudi.anto New Member

    Dear All,
    Could you help me, i want to get the number of week in a month example when the day is Friday Jan, 2, 2009
    I get the value 1 (or the first week) when the day is Tue Jan, 6, 2009 i get the value 2 ( or the second week).
    Thanks & Regards
  2. FrankKalis Moderator

    This really depends on how you define "week", but this should get on going:
    DECLARE @TheDate datetime;
    SELECT @TheDate = '2009-01-06';

    DATEDIFF (week, DATEADD (m, DATEDIFF (m, 0, @TheDate), 0), @TheDate) + 1

Share This Page