Hi

Given a date of say 15/5/2006 13:00 and then given a time span of say 1 day, how do i then halve that date?

**There is a few catches**

1) Must take into consideration weekends

2) Must take into consideration working hours

As an example, today is the 5th June, if i have a time span of 1 day.

Add one day to 5th June 13:30 = 6th June 13:30

Halve one day (which is based on a 9-5 day, so 4 hours) = 6th June 09:30

Simple :o)

So, if was 6th June at 10:00 and you halved a day and subtracted it, taking into consideration working days it would work out to be the day before because it would be before 9am. Same applies to weekends.

How do i do this with SQL?????

Many Thanks

Select startdate

,case Datepart(dw,X)

When 6 then Dateadd(d,2,x)

else x

end as x

from (

Select Case when Datepart(hh,x) >= 17

Then DateAdd(s,

dateDiff(s,convert(char(8)

,Dateadd(d,1,Convert(char(

else x

end as x

,startdate

from (

select dateadd(hh,4,StartDate) as X,startdate

from (select '20060605 10:30:00' as startdate

union select '20060605 14:30:00'

union select '20060602 14:30:00'

) as qq

) as Y

) as z