Hello, help out there is a piece of the program: C #

if (DateTime.Now.Hour == 10 && DateTime.Now.Minute == 0) { <code>zsutcmd1.Parameters.AddWithValue("@DataTime", s); zsutcmd1.Parameters.AddWithValue("@SutCMC", save_txt31_CMC); zsutcmd1.Parameters.AddWithValue("@SutCMCSirieTanki", save_txt31_CMCSirieTanki); zsutcmd1.Parameters.AddWithValue("@SutHotCMC", save_txt31_HotCMC); zsutcmd1.Parameters.AddWithValue("@SutCMCCIP", save_txt31_CMCCIP); zsutcmd1.Parameters.AddWithValue("@SutCMCCIPObram", save_txt31_CMCCIPObram); zsutcmd1.Parameters.AddWithValue("@SutCMCRozliv", save_txt31_CMCRozliv); zsutcmd1.Parameters.AddWithValue("@SutCMC3", save_txt31_CMC3); zsutcmd1.Parameters.AddWithValue("@SutCMCTara", save_txt31_CMCTara); } if (DateTime.Now.Hour == 10 && DateTime.Now.Minute == 5 && DateTime.Now.Second == 00) { zsutcmd1.Parameters.AddWithValue("@DataTime", s); zsutcmd1.Parameters.AddWithValue("@SutCMC", 0); zsutcmd1.Parameters.AddWithValue("@SutCMCSirieTanki", 0); zsutcmd1.Parameters.AddWithValue("@SutHotCMC", 0); zsutcmd1.Parameters.AddWithValue("@SutCMCCIP", 0); zsutcmd1.Parameters.AddWithValue("@SutCMCCIPObram", 0); zsutcmd1.Parameters.AddWithValue("@SutCMCRozliv", 0); zsutcmd1.Parameters.AddWithValue("@SutCMC3", 0); zsutcmd1.Parameters.AddWithValue("@SutCMCTara", 0); } else { } 

The question is how to make the if statement work with minutes if you take

 if (DateTime.Now.Hour == 10 && DateTime.Now.Minute == 0) 

works fine, but if I add minutes:

 if (DateTime.Now.Hour == 10 && DateTime.Now.Minute == 5 && DateTime.Now.Second == 00) 

then he immediately stops working, and at the same time there is still a place that once a month is the first day, tell me how to do it correctly: for a month it looks like this:

 if (DateTime.Now.Day == 1 && DateTime.Now.Hour == 7 && DateTime.Now.Minute == 0) 

but for some reason it seems to me that he, too, was working out

  • What does it mean to stop working? - Nick Volynkin
  • And you precisely pull this function every second? It can not be that she is twitching in 59..01..03..05 seconds, for example? - Kromster
  • Make a DateTime.Now.Minute output, look what it is, you are most likely writing in the wrong format in if . - Denis
  • It stops working in the sense that it does not work out the code that is in it, the code is in the correct format, I don’t jerk it every second, I jerk it once at 10 00, the second time at 10:05 - by Andrey Kalinin

1 answer 1

Most likely, the fact is that the second is not zero at the time of execution.

Make a check without seconds but with the flag that this minute worked, for example:

 if (DateTime.Now.Hour == 10 && DateTime.Now.Minute == 5 && last_minute < DateTime.Now.Minute) { last_minute = DateTime.Now.Minute; ... } 

But in general, it is more correct to make a shepherdier for this business, which will be called in at the right period or at the right time.

  • Does not work out, can you give more details? - Andrey Kalinin