结束日期应比开始日期大两年 [英] End Date should be two years Greater than start date

查看:133
本文介绍了结束日期应比开始日期大两年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有两个包含开始日期和结束日期的日历..

>结束日期应该是两年多比开始日期...

如果低于两年就应该抛出错误..



解决这个问题的任何解决方案.. ..

Hi,

I have two calendars with start date and end date ..
>end date should be two years more than start date...
if it is below two years it should throw an error..

any solution to solve this ....

推荐答案

如果你减去两个日期,你得到的差异是TimeSpan - 这很好,除了它是与日期无关的,所以它没有一个长度比一天长的房产 - 如果你考虑它就很有意义,因为几周,几个月等都取决于日期。



什么你真正想要的是年龄而不是日期之间的差异。

看看这个:与年龄合作:它与TimeSpan不同! [ ^ ] - 它在C#而不是VB,但它应该非常明显,如果你不能在线转换器应付自己!
If you subtract two dates, you get the difference as a TimeSpan - which is fine, except it is date independent, so it doesn''t have a property with a longer length than the day - which makes good sense if you think about it, since weeks, months etc, are all dependant on teh date.

What you actually want is the Age of something rather than a difference between to dates.
Have a look at this: Working with Age: it''s not the same as a TimeSpan![^] - it''s in C# rather thn VB, but it should be pretty obvious and there are on-line converters if you can''t cope yourself!


是的,你编写代码。您甚至不知道您拥有什么样的UI,无论是Web还是Windows,ASP.NET或MVC,winforms还是WPF?没有人可以提供帮助,基于此,你还没有提供任何信息。即使你向我们展示了你的代码,我们也能填补你没告诉我们的空白。



基本上,无论平台如何,您可以在控件上设置范围,但是您可以使用一个事件来检测选择是否在您接受的范围内,如果不是,您可以显示一条消息,然后将其更改为是。如果它总是要好两年,那么它就更容易了,只需自己设置,为什么用户需要在知道它时选择一个值?为什么要显示日期选择器?
Yes, you write code. You don''t even say what sort of UI you have, is it web or windows, ASP.NET or MVC, winforms or WPF ? No-one can help, based on this, you have just not given any information. Even if you showed us your code, we''d be able to fill the gaps in what you''re not telling us.

Basically, whatever the platform, you may be able to set a range on the control, but you WILL have an event you can use to detect if the selection is within your accepted range and if it''s not, you can show a message, and change it so it is. If it is always to be EXACTLY two years greater, then it''s even easier, just set it yourself, why should the user be required to select a value when you know it ? Why show a date picker then at all ?


这篇关于结束日期应比开始日期大两年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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