Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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");
}
Posted
Updated 15-Mar-17 3:16am
v2
Comments
Prateek Dalbehera 15-Mar-17 8:26am    
Can you elaborate more what you want to achieve. BTW you can use TimeSpan for time calculation and write your logic in it.
Scribling Doodle 15-Mar-17 8:30am    
I have 2 separate dates, the today's date and the end date of that subscription. What I want is simply remind me 5 days before the end date is equal to the today's date. It's kinda confusing yeah, but I hope you understand!
Prateek Dalbehera 15-Mar-17 8:34am    
ok, how frequently is your application running? I mean to ask that how frequently the DateComparison method will be called?? Do you want something like if (Endday - Today <= 5) then show alert??
Scribling Doodle 15-Mar-17 8:37am    
Daily Basis, It's a subscription program for a Gym. Which needs constant updates on the end dates, so the worker can warn the people.
Prateek Dalbehera 15-Mar-17 8:40am    
Is the solution provided below not helping you?? It will return bool value according to date range. Or do you require something else?

1 solution

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

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;
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900