比较日期和今天的日期 [英] compare date to today's date

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

问题描述

我现在有一个包含到期日期的文本框,我必须将该文本框与大于或等于今天的日期进行比较.我只有一个文本框.与今天的日期相比如何?请帮助我

I have a textbox that contain expiry date now i have to compare that textbox to greater then or equal to today date. I have only one textbox. how it will be compare to today date please help me

推荐答案

C#:
DateTime dtToday = new DateTime();
DateTime dtToCheck = Convert.ToDateTime(txtExpiryDate.Text);
if(dtToCheck >= dtToday)
{
  // Things are Ok for now
}
else
{
  // Expired.
}



客户端Javascript代码的类似逻辑.它也具有"Date"对象,并且具有直接的日期比较.



Similar logic for client side Javascript code. It too has ''Date'' object and has direct date comparison.


hii

您的代码是

DateTime date1 = DateTime.Now();
DateTime date2 = Convert.ToDateTime(txtExpiryDate.Text);

int结果= DateTime.Compare(date1,date2);
字符串关系=";

如果(结果< 0)
关系=早于";
否则,如果(结果== 0)
关系=与……同时";
其他
关系=晚于";

Console.WriteLine("{0} {1} {2}",date1,Relationship,date2);
hii

your code is

DateTime date1 = DateTime.Now();
DateTime date2 = Convert.ToDateTime(txtExpiryDate.Text);

int result = DateTime.Compare(date1, date2);
string relationship="";

if (result < 0)
relationship = "is earlier than";
else if (result == 0)
relationship = "is the same time as";
else
relationship = "is later than";

Console.WriteLine("{0} {1} {2}", date1, relationship, date2);


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

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