ericthesialie
ericthesialie

Reputation: 23

Convert string into datetime in razor view with javascript?

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>';
}

Upvotes: 0

Views: 2074

Answers (2)

Corwin Schmitz
Corwin Schmitz

Reputation: 70

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
           }
    }

Upvotes: 1

Mukesh Modhvadiya
Mukesh Modhvadiya

Reputation: 2178

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

if(new Date("your date string") <= Date.now)
{
    // your code
}

Upvotes: 1

Related Questions