Last active
May 22, 2019 15:27
-
-
Save SergiyOsadchyy/e9d090d63ca5937f30c5903c7f3a6e5c to your computer and use it in GitHub Desktop.
DateTime.Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var stringDate = "20190130"; | |
var startDate = new DateTime(2019, 01, 30); | |
var endDate = new DateTime(2019, 02, 20); | |
var testDate = new DateTime(2019, 02, 01); | |
var result1 = DateTime.Compare(testDate, startDate); | |
var result2 = DateTime.Compare(testDate, endDate); | |
Console.WriteLine(result1); // 1 | |
Console.WriteLine(result2); // -1 | |
if (DateTime.Compare(testDate, startDate) >= 0 && DateTime.Compare(testDate, endDate) <= 0) | |
{ | |
Console.WriteLine("It is inside"); | |
} | |
else | |
{ | |
Console.WriteLine("It is outside"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment