browner
Mar 30th, 2000, 06:27 PM
Does anyone know how to use the DateDiff function to return the number of workdays (M-F) between two dates in SQLServer. Or is there any other function you can use. Can you write your own functions to use in views? If anyone has any ideas I would appreciate your comments.
Thanks
JHausmann
Mar 31st, 2000, 01:50 AM
Select DATEDIFF(day,datefield1,datefield2) will get you the number of days
Select DATEDIFF(week,datefield1,datefield2) will get you the number of weeks
You might be able to do something like, but it won't be precise.
declare @numWrkDays Int
declare @numDays Int
declare @numWeeks int
Select @numDays = DATEDIFF(day,datefield1,datefield2)
Select @numWeeks=(DATEDIFF(week ,datefield1,datefield2)
Select @numWrkdays = @numdays - (@numweeks *2)
To answer your other questions, you could write an extended procedure in C/C++ that could be called from a script (if one doesn't already exist).