subtracting minutes from a DateTime

Socks93

Active member
Joined
Oct 22, 2021
Messages
29
Programming Experience
Beginner
Can anyone help me subtracting minutes from a DateTime


C#:
public DateTime AddMinutes(double value);


if (connection.Value.Disconnected > DateTime.Now - AddMinutes(AppConfig.current.DisconnectTimerMins))
{
              
}

Can anyone help me with this?

Thanks
 
Last edited:
Your code doesn't make sense as it is. Think about the logic, then write the code to implement the logic. AddMinutes is an instance method, which means that you call it on a DateTime value. It can't just be called out in space like you're doing. Think about basic arithmetic. What is the result if you add a negative number? It's the same result as subtracting a positive number, right? So, if there's no SubtractMinutes method but there is an AddMinutes method and you want to subtract minutes, what are you going to do?

Also, you don't even have to subtract anyway. You could add the number of minutes to the first value and that would produce exactly the same result as subtracting the number of minutes from the second value.
 
Or they could have just looked at the documentation and seen how to use the AddMinutes() method of DateTime...

 
Back
Top Bottom