Don't convert dates to strings in order to convert them: convert strings to DateTime and compare those.
Equally, if it's a DATETIME, DATETIME2 or DATE column in SQL, then it automatically converts to a DateTime in C# (as it's stored in both as a number of ticks since a defined point in time).
Your code is failing because you
are converting a DateTime to a string, and getting it wrong:
DateTime.Now.ToString("yyyy-mm-dd hh:mm:ss:nnn", CultureInfo.InvariantCulture)
^
|
The format code "mm" is the minutes, not the month:
Formatting a DateTime for display - format string description[
^]