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>';
}
3
  • Possible duplicate of: stackoverflow.com/questions/1576753/… Commented Jun 4, 2014 at 8:00
  • Why are you converting it to a string? Commented Jun 4, 2014 at 8:03
  • cause i cant get the data into my table if i dont convert it to string in my controller sir Commented Jun 4, 2014 at 8:05

2 Answers 2

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
}
Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

any idea how to fill my string with datetime ?
with all answer i try,the problem is the same,its not enter the if statement,cause it cant compare the string with Date.Now;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.