Question: I need to calculate the average days within the specified datetime values in sql server which involves the logic day+(hh + mm + ss + mi) as the average time(days).
can anybody help me?

thanks in advance...

Answer: 
You can use the [datediff](http://msdn.microsoft.com/en-us/library/ms189794.aspx) function:

```
SELECT DATEDIFF(day, startdate, enddate)
FROM myTable

```

That will give you the number of days between two dates.

You can get the average with the [AVG](http://msdn.microsoft.com/en-us/library/ms177677.aspx) function:

```
SELECT AVG(DATEDIFF(day, startdate, enddate))
FROM myTable

```
And just in case your enddate may be null, try this

```
select case when (SubscriptionEnd is null) 
then datediff (day,SubscriptionStart,getdate())
else datediff (day,SubscriptionStart,SubscriptionEnd)
end as 'totaldays'
from [dbo].[whatever]

```