2015-11-11 204 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); 

然後你就可以這麼最低數量是在開始(或結束)的陣列進行排序,並返回一個。