我對它有一個TextBox和Extender AjaxCalander。在選擇日期時,它在TextBox中的工作狀態很好,只顯示月份和年份。我的代碼如下datetime(month + year)與字符串的比較
<asp:TextBox ID="txtCardExpiry" runat="server" Width="200px" /><span> MMYY</span>
<ajaxToolkit:CalendarExtender runat="server" Format="MMyy" TargetControlID="txtCardExpiry" />
我想我現在該怎麼比較txtCardExpiry.Text
與今天月份和年份只有
現在即時通訊使用
int dtNowYear = Convert.ToInt16(DateTime.Now.Year.ToString().Substring(2, 2));
int dtNowMonth = Convert.ToInt16(DateTime.Now.Month.ToString());
int dtExpYear = Convert.ToInt16(txtCardExpiry.Text.Substring(2, 2));
int dtExpMonth = Convert.ToInt16(txtCardExpiry.Text.Substring(0, 2));
if (dtNowYear == dtExpYear && dtNowMonth > dtExpMonth)
{
lblMessage.Attributes.Add("class", "lblMessageError");
lblMessage.Text =
"Credit Card expiry month and year cannot be less than todays month and year or your Credit Card has expired";
return false;
}
else if (dtNowYear > dtExpYear)
{
if (dtNowMonth > dtExpMonth)
{
lblMessage.Attributes.Add("class", "lblMessageError");
lblMessage.Text =
"Credit Card expiry month and year cannot be less than todays month and year or your Credit Card has expired";
return false;
}
return false;
}
只是與asp.net –