Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I get an AVERAGE from a DATETIME field?

Status
Not open for further replies.

LeonelSanchezJr

Programmer
Jan 26, 2001
522
US
Can I get an AVERAGE from a DATETIME field?
 
That was interesting.

This seems to work but I have not tested it extensivly.

dateadd(day,avg(datediff(day,'1900-01-01',mydate)),'1900-01-01')
 
it is an arbitary date to get the difference from. Probably any date would do.

Since sql server won't average a date. I am using datediff to calculate the number of days from an arbitrary date 1/1/1900, and averaging that. DateAdd changes that number back to a date.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top