0

In my controller I convert the datetime into string

here's the code

var result = from c in displayedCustomers select new[] { c.NonActiveDate.ToString("dd-MM-yyyy HH:mm:ss")};

and I want to convert it back to datetime cause I want to compare it with today date

this is my code and not working cause the string cannot be compare with date

if (d <= Date.now)
{
    return '<span style = "color : red">' + oObj.aData[4]+ '</span>';
}
ohlmar
  • 958
  • 8
  • 17

2 Answers2

1

cant you fill another string with the date time now and compare them that way.

    {
            var time = DateTime.Now;

            string Time = time.ToString();

           if(yourtimevariable == Time)
           {
            //enter what you want to do when the if statement is true
           }
    }
1

Convert your string to Date object in java script using "Date" function before comparing

if(new Date("your date string") <= Date.now)
{
    // your code
}
Mukesh Modhvadiya
  • 2,178
  • 2
  • 27
  • 32