Is there between DateTime in C# ? I know I can do simple check with if (a > date1 && a < date2)
but I was trying to find Between
method.
The difference between two dates can be calculated in C# by using the substraction operator - or the DateTime. Subtract() method. The following example demonstrates getting the time interval between two dates using the - operator.
There is not a Between
function but should be easy enough to add one
public static bool Between(DateTime input, DateTime date1, DateTime date2) { return (input > date1 && input < date2); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With