如何查看今天的日期是否为结束日期的5天? [英] How can I check if today's date is 5 days from ending date?

查看:91
本文介绍了如何查看今天的日期是否为结束日期的5天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张包含3个日期的表格。注册日期,结束日期和实际日期。

我想要的只是向我展示一个文本框,它可以提醒我结束日期是在5天内和结束日期发生的。例如:



我的结束日期设置为4-5-17,实际日期为29-4-17。它应该做的是,当日期是结束后的-5天,它会向我显示警告,然后当结束日期等于今天的日期时,它将显示我设置为编辑日期的表格。 br />


我尝试过:



试图将日期转换为字符串当日期到达时,将-5减去结束日期并将消息框减去。



I have a table that includes 3 dates. The registered date, the ending date and the actual date.
What I want is to simply show me a textbox that could remind me that the end date is happening in 5 days and on the end date. For example:

I have a "end date" set to 4-5-17 and the "actual date" is 29-4-17. What it should do is that it would show me a warning when the date is -5 days from ending, and then when the end date is equal to today's date it will show me a form that i've set to edit the date.

What I have tried:

Tried to convert date to string and subtract -5 to the end date and messagebox me when the date is reaching.

string actualdate;
string enddate;
enddate = dr.Cells["Até"].Value.ToString();
actualdate = DateTime.Now.ToString();
if (actualdate > enddate)
{
    MesageBox.Show("The end date of "dr.Cells["Name"].Value" subscription is ending!","Warning");
}

推荐答案

引用:

尝试将日期转换为字符串并将-5减去结束日期,并在日期到达时将消息框减去。

Tried to convert date to string and subtract -5 to the end date and messagebox me when the date is reaching.



不要这样做!相反,将其保留为DateTime值:


Don't do that! Instead, keep it as a DateTime value:

private bool IsWithinDays(DateTime date, int numberOfDays)
    {
    return DateTime.Now.Date.AddDays(numberOfDays) >= date;
    }


这篇关于如何查看今天的日期是否为结束日期的5天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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