日期交叉算法 [英] date intersection alogorithm

查看:176
本文介绍了日期交叉算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



请帮助,

卡在日期交叉路口:



我需要一个函数来获得2个日期对之间的共同日期范围。



Ex。对1 = 2010年3月1日,2011年3月10日

对2 = 2011年3月1日,2012年3月12日



现在在这种情况下交易是2011年3月1日至2011年3月10日。



我尝试的是:



插入两个日期范围数据表中的详细信息然后在两个表中应用匹配函数用于常见日期并存储在diff中。表。



但我对此不满意。



请帮助..


  • 使用.NET类型 System.DateTime 表示与时间间隔的起点和终点相对应的时刻。
  • 了解此时的实例代表单个时间点,不要试图将其分为日期和时间,转换为任何东西,考虑结构的单独组件等。
  • 使用为类型 System.DateTime
  • 不要忘记清理输入数据;特别要记住的是,输入可能包含零或负时间间隔,当起点和终点相同或结束时,在起始点之前。
  • 应用简单的逻辑。




祝你好运,

-SA


Dear All,

Please help ,
Got stuck on date intersection:

I need a function for getting common date range between 2 date pairs.

Ex. pair 1= 1 mar 2010 ,10 mar 2011
pair 2= 1 mar 2011 , 12 mar 2012

now in this scenario the transaction is 1 mar 2011 to 10 mar 2011.

What I tried is:

insert both date range details in datatable and then applied a match function for common dates in both tables and stored that in diff . table.

But I am not satisfied with this.

please help..

解决方案

Do the following:
  • Use .NET type System.DateTime to represent moments of time corresponding to the starting and ending points of the time interval.
  • Understand that the instance of this time represent a single point in time, don't try to split it into date and time, convert to anything, consider separate components of the structure, etc.
  • Compare two points of time using '>=' operator defined for the type System.DateTime
  • Don't forget to sanitize input data; in particular, keep in mind that input may contain zero or negative time interval, when starting and ending points are the same or "ending" one precedes the "starting" one.
  • Apply simple logic.


Good luck,
—SA


这篇关于日期交叉算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆