2015-11-11 300 views
-5

我想查找记录之间最短日期/时间的日期/时间。在具有多个记录的表格中。日期/时间比较

Fx。

- 11/11-15 13:00 
- 11/11-15 15:30 
- 11/11-15 16:45 <= (find this record) 
- Timenow (11/11-15 18:33) the current record i want to create but i need to compare the old dates with. 

我无法创建逻辑,帮助!

感谢

+2

请阅读[**如何问**](http://stackoverflow.com/help/how-to-ask) \t \t \t和[**如何创建一个最小的,完整的,并且可验证的例子。**](http://stackoverflow.com/help/mcve) 这是一个很好的开始\t http://spaghettidba.com/2015/04/24/how-to-post-at-sql -question-ON-一个公共论坛/ –

回答

-1

您可以创建一个返回两个日期之间的差异的功能,运行所有通过此功能可能的日期,然后选择最低的差异。

是这样的(伪C代码)

int array[numdates]; 
for (int i=0;i<numdates;i++) 
    array[i]=compareDates(date[index], currentDate); 

然后你就可以这么最低数量是在开始(或结束)的阵列进行排序,并返回一个。