Wednesday, March 19, 2008
Yesterday, my friend Ilya asked me how to perform average for dates. I explained him that actually, the dates in SQL Server are represented as numbers, where zero is 01/01/1900. All you need to do is to cast the dates to numbers, make average on them and getting the result back as date. Assuming that the date column called MyDate, Here is the code:

Cast(Avg(cast(MyDate as float)) as datetime)

Thursday, July 17, 2008 12:53:17 AM (Jerusalem Daylight Time, UTC+03:00)
This is a great example, if I wanted the average of the Time component only would this work as well. I noticed I cannot convert time to float.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):