Contact Me

Nirav Prabtani

Mobile : +91 738 308 2188

Email : niravjprabtani@gmail.com

Nirav Prabtani

Wednesday 16 July 2014

How to get Friday dates in a Month sql

How to get Friday dates in a Month


try this.. Smile | :) 

declare @DateFrom datetime,@DateTo datetime
set @DateFrom='23 Mar 2014'
set @DateTo='26 Jun 2014'
 
;WITH CTEQuery AS (
 SELECT CAST(@DateFrom AS DATETIME) AS dt
 UNION ALL
 SELECT DATEADD(dd, 1, dt)
  FROM CTEQuery s
  WHERE DATEADD(dd, 1, dt) <= CAST(@DateTo AS DATETIME)
  ),sampleData as(
select dt,datename(WEEKDAY,dt)as [DayName] from CTEQuery )
select * from sampleData where [DayName]='Friday'

you have to just pass @DateFrom and @DateTo from code behind and you will get all friday dates between there dates.. Smile | :)

No comments :

Post a Comment