'run e edited dont rededit its danger
The first If yuuyworked but other Wwork i don't really know why. also ELSE ll, llseems like when i ydays it yfunction with me.
string today = "999/9";
if (today == DateTime.Now.ToString("dd/MM/yyyy"))
Application.Run((Form) new Program.());
so if u still don't understand what i need is, i need the application form to run after a specefic date like above 13/03/2022 so after todays date which is 13/03/2022 has passed and 14/03/2022 has passed ( because i added 1 day ) and 15/03 ( because i added 2 day ) has passed then anything else run the ( else ) statement. i test by changing my pc date and time by days FIRST IF statement worked and ELSE statement worked. but the added days one dosent work. any alternative way?
Solution 1:[1]
string today = "13/03/2022";
if (today == DateTime.Now.ToString("dd/MM/yyyy"))
Application.Run((Form) new Program.Notification.NotificationForm());
else if (today == DateTime.Now.AddDays(1).ToString("dd/MM/yyyy"))
Application.Run((Form) new Program.Notification.NotificationForm());
else if (today == DateTime.Now.AddDays(2).ToString("dd/MM/yyyy"))
Application.Run((Form) new Program.Notification.NotificationForm());
else
Application.Run((Form) new Program.Notif2.NotificationForm());
From your post, I think the if setences should be constructed like above.
As for the adding days testing, since you defined today as 13/03/2022, you'll need to set pc time to
12/03/2022to test +1day11/03/2022to test +2day.
Your variables might need to change names, because DateTime.Now is the real date of today (in your system), while today, the string variable, is set to be a certain date, which is confusing.
Solution 2:[2]
Change the comparrison type and reduce the if statements to if/else
DateTime today = new DateTime(2022, 03, 13);
if (today >= DateTime.Today && today <= DateTime.Today.AddDays(2))
Application.Run((Form)new Program.Notification.NotificationForm());
else
Application.Run((Form)new Program.Notif2.NotificationForm());
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Xiang Wei Huang |
| Solution 2 |
