Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Summing Columns of Dates Expand / Collapse
Author
Message
Posted Saturday, August 04, 2012 3:14 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, January 05, 2013 7:06 PM
Points: 15, Visits: 42
I have 2 columns of dates. What I need to do is to sum or count days in between. I know that there is the Datediff function. My problem is that I am trying to sum a startdate and an enddate. But if the start date starts on 6/1/2012 and ends on 6/1/2012 then I want to count this as 1. Can anyone please give me some guidance thanks in advance!
Post #1340220
Posted Saturday, August 04, 2012 4:47 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 11:40 AM
Points: 22,509, Visits: 30,227
pkaraffa (8/4/2012)
I have 2 columns of dates. What I need to do is to sum or count days in between. I know that there is the Datediff function. My problem is that I am trying to sum a startdate and an enddate. But if the start date starts on 6/1/2012 and ends on 6/1/2012 then I want to count this as 1. Can anyone please give me some guidance thanks in advance!


DATEDIFF(dd,@StartDate,@EndDate) + 1



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1340225
Posted Sunday, August 05, 2012 2:03 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, April 09, 2014 9:03 PM
Points: 1,128, Visits: 1,161

case when @StartDate<@EndDate then
DATEDIFF(dd,@StartDate,@EndDate) + 1
when @StartDate>@EndDate then DATEDIFF(dd,@StartDate,@EndDate) - 1 end


~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one
Post #1340248
Posted Sunday, August 05, 2012 2:35 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, January 05, 2013 7:06 PM
Points: 15, Visits: 42
Thank you both worked great!
Post #1340292
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse