Sql query to get week number from current or specific date

In this article I am going to explain how to get the week number from current and specific date in sql server.


Implementation:

Sql server query to get Current week number:

select [Current Week Number]= datepart(dw, getdate())


Sql server query to get week number of specific date:

declare @date datetime = '2016-01-25'
select [Week Number is] = datediff(week, dateadd(week, datediff(week, 0, dateadd(month, datediff(month, 0, @date), 0)), 0),
@date - 1) + 1

 OUTPUT:
Sql query to get week number from current or specific date




Post a Comment

0 Comments