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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 DateTime

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-05-17 : 09:47:53
Brian writes "This is probably simple I just don't know how to do it.
I need a query statement that will return a date that is half way between two dates that I have in my SQL.
fields are programbegin and programend. I need to find the mid point between these two dates? Any help would be appriciated."

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-05-17 : 10:03:24
Adjust this depending on ur requirement


Create table #t (programbegin datetime, programend datetime)
Insert into #t values('01/01/2006','01/31/2006')
Insert into #t values('01/10/2006','01/20/2006')
Insert into #t values('02/01/2006','02/28/2006')
Insert into #t values('03/01/2006','01/21/2006')

Select programbegin + datediff(dd,programbegin,programend) / 2 from #t


Srinika
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-18 : 03:00:02
or

Select DateAdd(day,DateDiff(day,programbegin,programend)/2, programbegin) from #t


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -