我只想比较不超过3个月. [英] I want just compare not more then 3 months.

查看:91
本文介绍了我只想比较不超过3个月.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我们有两个文本框.

现在我只想比较不超过3个月.

问题:date1不超过3个月date2

我找到了这样的选定月份.

Hello,

We have two text-box.

Now I want just compare not more then 3 months.

Question: date1 is not more then 3 months date2

I have found selected month like this.

DateTime date1 = Convert.ToDateTime(TextBox1.Text);
     DateTime date2 = Convert.ToDateTime(TextBox2.Text);

     int mon1 = date1.Month;
     int mon2 = date2.Month;


谢谢,

推荐答案

DateTime date1 = Convert.ToDateTime(TextBox1.Text);
DateTime date2 = Convert.ToDateTime(TextBox2.Text);
       
int monthsDiff = (date1.Month - date2.Month) + 12 * (date1.Year - date2.Year);


我通常使用TimeSpan.FromXXX方法执行以下操作:

I usally use the TimeSpan.FromXXX methods to do something like this:

if((myDate - myOtherDate) > TimeSpan.FromSeconds(10))
{
   //Do something here
}







or

//30 is days..
if (DateTime.Compare(date1, date2) < 30)
{
   //Do something here
}




--Amit




--Amit


这篇关于我只想比较不超过3个月.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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