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 2005 Forums
 Transact-SQL (2005)
 Get the date difference

Author  Topic 

d3ng
Yak Posting Veteran

83 Posts

Posted - 2009-05-31 : 22:00:30
Hi SQL experts,

I would like to ask on how to get the date difference of 2 dates

(Sample Date)
regdate
2009-05-25 09:30:00

current date
2009-06-01 11:00:00

(The results should be like this)
Results : 7 Days 1hr 30 mins

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-31 : 22:36:42
[code]
select tot_mins,
days = tot_mins / (24 * 60),
hours = (tot_mins / 60) % 24,
mins = tot_mins % 60
from
(
select tot_mins = datediff(minute, '2009-05-25 09:30', getdate())
) m[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

d3ng
Yak Posting Veteran

83 Posts

Posted - 2009-05-31 : 23:02:17
thanks! it works!
Go to Top of Page

SQLRatankalwa
Starting Member

42 Posts

Posted - 2009-06-01 : 12:03:27
You can also use

select DATEDIFF(MI , '2009-05-25 09:30', Getdate()),
DATEDIFF(MI , '2009-05-25 09:30', Getdate()) / (24 * 60),
DATEDIFF(MI , '2009-05-25 09:30', Getdate()) % 24,
DATEDIFF(MI , '2009-05-25 09:30', Getdate()) % 60



Ratan Kalwa
SQL Server Professionals User Group

http://www.revalsys.com
Go to Top of Page
   

- Advertisement -