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 |
tuan83vnn
Starting Member
4 Posts |
Posted - 2012-03-14 : 22:56:05
|
Hi,My database have two fields:startdate,stopdateexp:startdate : 2012-01-02 20:15:11.123stopdate: 2012-01-03 20:15:11.123 I used datediff to get the second between two fields:datediff(milisecond,startdate,stopdate)/1000but result = NULLIf startdate and stopdate have the same date, query return the true result. And if they have different date, result is null.Please help, thanksTuanTran |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-03-14 : 22:59:25
|
[code]datediff(millisecond,startdate,stopdate)/1000[/code]or divide by 1000.0 if you want it in decimalDo note that you will get overflow if the different in 2 dates is huge. If you do not required that accuracy, just find the different in terms of seconds. The date different in Second will also hit that overflow problem, it is just the range is larger. KH[spoiler]Time is always against us[/spoiler] |
|
|
tuan83vnn
Starting Member
4 Posts |
Posted - 2012-03-14 : 23:26:47
|
The result is trueThanks khtan so much,TuanTran |
|
|
|
|
|
|
|