我想使用两(2)个datepicker
在给定日期之间的2个月内验证日期示例:DATEPICKERdatefrom = 02/05/2013 and DATEPICKERdateto = 03/08/2013(dd / mm / yyyy)
我的陈述应该是什么?
if ( /*DATEPICKERdatefrom between DATEPICKERdateto is not between 2 months*/ )
{
messagebox.show("the Date must within 2 months")
}
else
{
//GO
}
答案 0 :(得分:0)
这是一个如何抵消日期的例子。
DateTime twoMonthsBack = DateTime.Now.AddMonths(-2);
DateTime twoMonthsLater = DateTime.Now.AddMonths(2);
您可以将示例中的DateTime.Now
替换为您的日期。你可以选择验证它。
也许
if(DATEPICKERdateto > DATEPICKERdatefrom.AddMonths(2))
{
//to date is more than two months from start date
messagebox.show("the Date must within 2 months");
}
else
{
//GO
}
以上示例基于以下假设:从日期开始总是少于迄今为止。
答案 1 :(得分:0)
如果这些值为DateTime
,您只需使用<
或>
运算符进行比较。
if((date > DATEPICKERdatefrom) && (date < DATEPICKERdateto))
DateTime
as;
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public static bool operator < (DateTime t1, DateTime t2) {
return t1.InternalTicks < t2.InternalTicks;
}
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public static bool operator > (DateTime t1, DateTime t2) {
return t1.InternalTicks > t2.InternalTicks;
}