1

I'm using ng-show in a page that I'm creating:

<td ng-show="week.EndDate > controller.currentDate">

where week is an object with a property EndDate and currentDate is set in my controller:

currentDate = new Date();

My ng-show fails whether I set the dates >, <, or =. I printed out my dates and this is what they are:

week.Date = 2014-11-07 controller.currentDate = 2015-07-09T21:54:40.655Z

I'm not sure if the issue is being caused by the difference in format or not. If so how can I correct this, if not, is there another way to compare dates?

1
  • 1
    currentDate is a Date object, likely week.Date is a string. Commented Jul 9, 2015 at 22:08

1 Answer 1

1

You should either convert your week.EndDate string to a Date object or wrap your comparison in a function that converts it to a date.

ng-show="convertToDate(week.EndDate) > controller.currentDate"

The only thing you need to keep in mind is that if you convert week.EndDate permanently to a Date object you might need to convert it back to your desired format when you want to store it somewhere for example.

Sign up to request clarification or add additional context in comments.

Comments

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.