Monday, August 21, 2017

C# date comparison MVC Razor

Issue:
I had a problem with a conditional test which was failing.  I was trying to compare two dates but the condition was not firing in my view.




claimPayments.Payment_Date.Value.ToString("dd-MMM-yyyy") == temp.ToString("dd-MMM-yyyy")


changed it to


claimPayments.Payment_Date.Value.Ticks.Equals(temp.Ticks)


This fixed the problem.  Using the ticks function gets around the issue of trying to match date formats.



No comments:

Post a Comment