Date & time query question (SQL Server 2008)
Translations
Englishالعربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
I have table that contain date and time field.
id|date|time
=========
1|01/01/2001|10:45
2|01/02/2002|11:45
3|01/03/2003|12:45
4|01/04/2004|12:55
I need to know the difference between the MAX(date) and the MIN(date)
And the MAX(time) and the MIN(time)
Something like.... MAX(date)-MIN(date) ???.....
Thanks in advance
This question and answers originated from www.stackoverflow.com
Question by Gold (3/19/2010 8:15:49 AM)
Answer |
DATEDIFF is your friend.
To get the difference in number of days: SELECT DATEDIFF(day, MIN(date), MAX(date)) FROM [table] = 1186
To get the difference in number of hours: SELECT DATEDIFF(hour, MIN(time), MAX(time)) FROM [table] = 2
To get the difference in number of minutes: SELECT DATEDIFF(minute, MIN(time), MAX(time)) FROM [table] = 130
Answer by Andy Shellam
Find More Answers
Related Topics sql-server-2008 query