Home > Mobile >  run e edited dont rededit its danger
run e edited dont rededit its danger

Time:03-17

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?

CodePudding user response:

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());

CodePudding user response:

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/2022 to test 1day
  • 11/03/2022 to 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.

  • Related