Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
waxdart23
Starting Member
33 Posts |
Posted - 2005-06-01 : 11:13:44
|
| If I have two columns containing dates in datetime format eg '2004-09-19 17:30:00.000' & '2004-09-24 14:30:00.000'How do I calculate the number of days between the two dates (in the case above 5 days) regardles of the time and store it as an int?ThanksP |
|
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2005-06-01 : 11:24:55
|
| Lookup the DATEDIFF functionMark |
 |
|
|
maninder
Posting Yak Master
100 Posts |
Posted - 2005-06-01 : 11:27:32
|
| Here is What we used to Calculate the number of days between 2 Dates.Create PROCEDURE Busdays @from_dt datetime,@to_dt datetime ,@wkends int outputASDECLARE@days int,@dp int ,@cnt intset @wkends=0set @cnt=0set @days=datediff(d,@from_dt,@to_dt)while @cnt <=@daysbeginset @dp=datepart(dw,dateadd(day,@cnt,@from_dt)) if @dp=1 or @dp=7set @wkends=@wkends+1set @cnt=@cnt+1EndManinder |
 |
|
|
waxdart23
Starting Member
33 Posts |
Posted - 2005-06-01 : 11:48:59
|
| DATEDIFF works great thanks for the pointerThanksP |
 |
|
|
|
|
|