Created
May 8, 2018 10:25
-
-
Save mraarif/6eb7432e3b3be96d0ec92e27e673050c to your computer and use it in GitHub Desktop.
How to compare DateTime in C# Ignoring milliseconds
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Utils | |
{ | |
public static class DateTimeComparisonExtensions | |
{ | |
public static bool EqualsUptoSeconds(this DateTime dateTime, DateTime dateTimeToCompare) | |
{ | |
if (dateTime.Date != dateTimeToCompare.Date) return false; | |
if (dateTime.Hour != dateTimeToCompare.Hour) return false; | |
if (dateTime.Minute != dateTimeToCompare.Minute) return false; | |
if (dateTime.Second != dateTimeToCompare.Second) return false; | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment