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.
| 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)regdate2009-05-25 09:30:00current date2009-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 % 60from( select tot_mins = datediff(minute, '2009-05-25 09:30', getdate())) m[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
d3ng
Yak Posting Veteran
83 Posts |
Posted - 2009-05-31 : 23:02:17
|
| thanks! it works! |
 |
|
|
SQLRatankalwa
Starting Member
42 Posts |
Posted - 2009-06-01 : 12:03:27
|
| You can also useselect 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()) % 60Ratan KalwaSQL Server Professionals User Grouphttp://www.revalsys.com |
 |
|
|
|
|
|
|
|