日期/时间比较 [英] Date/time comparison
本文介绍了日期/时间比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想找到记录之间的最小日期/时间的日期/时间.在具有多个记录的表中.
I want to find the date/time with minimum date/time between records. In a table with multiple records.
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.
我无法创建逻辑,帮助!
I can't create the logic, help !
谢谢
推荐答案
您可以创建一个函数,该函数返回两个日期之间的差额,通过该函数运行所有可能的日期,然后选择最小的差额.
You can create a function that returns the difference between two dates, run all the possible dates through this function, then pick the lowest difference.
类似这样的东西(伪C代码)
Something like this (pseudo c code)
int array[numdates];
for (int i=0;i<numdates;i++)
array[i]=compareDates(date[index], currentDate);
然后,您可以对数组进行排序,以便最小的数字在开头(或结尾)并返回该数字.
Then you can sort the array so the lowest number is at the beginning (or end) and return that one.
这篇关于日期/时间比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文