locked
If condition with date is not working in html RRS feed

  • Question

  • User-1355965324 posted

    I want to compare the date coming from the data from  a json file  and with todays date. The data coming from json  for example 17-07-2020 00:00:00 datetime   value without time in it . how can I check   with if condition whether the date is todays date or not . I given the code   as below but not working please help. DateTime.Now has time so that condition is failed

     @for (var i = 0; i < Model.consolidated_weather.Count(); i++)
            {
    
                <div style="display: inline-block;margin-right:15px">
                   
                    if(@Model.consolidated_weather[i].applicable_date== DateTime.Now)
                    {
                    <div>Today</div>
                    }
                    else
                    {
                    <div>@Model.consolidated_weather[i].applicable_date.ToString("ddd,dd-MMM")</div>
                    }



    Thursday, July 16, 2020 5:02 AM

Answers

  • User-1355965324 posted

    after giving  @if(@Model.consolidated_weather[i].applicable_date== DateTime.Now.Date), it is working fine

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 16, 2020 5:19 AM