Search code examples
c#.netwpfvisual-studioc#-4.0

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

  • 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.