i have 2 dates : date1 and date2 ; I want to check is that another date is between date1 and date2 thanks very much
You can just use the standard <, >, >= and <= operators:
if( someDate >= date1 && someDate <= date2 )
{
}
And, you can make your own extension method for it:
public static class DateExtensions
{
public static bool Between( this DateTime d, DateTime start, DateTime end )
{
return d >= start && d <= end;
}
}
Which you can use like this:
DateTime someDate = new DateTime (2012, 5, 6);
if( someDate.Between (date1, 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