Can't use '<=' to test less than/equal to between two DateTime values? RRS feed

  • Question

  • I'm working on an ASP.NET MVC 5 app and for some reason, it's not letting me use '<=' to test if one DateTime value is less than or equal to another DateTime value.  I'm doing this in a View (CSHTML) file by the way (which probably isn't the best place to do this).  This IF statement is also being done using Razor code (@).

    The reason I'm doing it here (in the actual HTML/CSHTML file) is because I need the table row to be different colors for the entire row depending on the date of the database record entry compared to the current system date.

    Here is my code:

    if (order.ShipByDate <= DateTime.Today)

    { // do something }

    (NOTE: order.ShipByDate is of the DateTime data type)

    Ideas or thoughts?  Is this just a limitation when using Razor code in HTML files?

    • Edited by cbassett82 Wednesday, August 30, 2017 3:48 PM
    • Moved by Sabah ShariqMVP Wednesday, August 30, 2017 3:50 PM Moved From Visual C#
    Wednesday, August 30, 2017 3:46 PM

All replies

  • Hi cbassett82,

    This is Visual C# forum. As your issue is related to Web please ask your question into ASP.Net forum for getting quick response. I am moving your thread to off topic.


    Your understanding and cooperation will be grateful.

    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]

    Wednesday, August 30, 2017 3:50 PM