Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there BETWEEN DateTime in C# just like SQL does?

Tags:

c#

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.

like image 690
MadBoy Avatar asked Apr 18 '11 21:04

MadBoy


People also ask

How do I get the time between two dates in C#?

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.


1 Answers

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); } 
like image 121
Bala R Avatar answered Sep 22 '22 03:09

Bala R