sql - DateDiff use current date if enddate is null -


i calculating 2 dates , returning days want exclude weekends , holidays. want say, if enddate null, use current date?

how do datediff?

or use this..

if object_id('tempdb..#holidays') not null drop table temp..#holidays create table #holidays(id int identity(1,1),holiday date) insert #holidays values ('2015-12-25'),('2015-12-28') set dateformat ymd declare @startdate date = '2015-12-01' declare @endtdate date = '2015-12-31' --some times @endtdate might null so, set getdate() set @endtdate = isnull(@endtdate,cast(getdate() date))  declare @holiday int  set @holiday = (select count(*) #holidays holiday between @startdate , @endtdate)  select    (datediff(dd, @startdate, @endtdate) + 1)   -(datediff(wk, @startdate, @endtdate) * 2)   -(case when datename(dw, @startdate) = 'sunday' 1 else 0 end)   -(case when datename(dw, @endtdate) = 'saturday' 1 else 0 end)   -@holiday 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -