0

I am building an AngularJS/Rails web app, part of it is creating bookings (function bookings) and in the dashboard I am trying to display two different tabs one with Current Bookings and one with Previous Bookings. the booking model has a function_date attribute and I am retrieving it from the API into a $scope.bookings array.

How to I compare dates (run an if statement on it) to do if function_data > today's date store it into CurrentBookings array if not store it into PreviousBookings array?

Hope that makes sense.

P.S. I am still teaching myself how to program so it might be a stupid question for some.

3
  • possible duplicate stackoverflow.com/questions/26435313/… Commented Apr 10, 2016 at 3:21
  • The issue I am having is date formatting, if I do as per the suggested article it doesn't work, as new Date(); produces 2016-04-10T03:35:00.128Z and my function_date comes in YYYY-MM-DD format Commented Apr 10, 2016 at 3:36
  • You can format new Date() to YYYY-MM-DD then the comparison will work. Look at this question for ways to format JS dates stackoverflow.com/questions/3552461/…. Also I recommend moment.js library but it may be overkill. Commented Apr 10, 2016 at 3:41

2 Answers 2

0

many way solved this problem but i am using to convert time in milliseconds then easy to compare.

var n = Date.now();

its give the current Return the number of milliseconds since 1970/01/01:

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

Comments

0

First, try converting your string into a date. Then compare it to now.

var date = new Date('2030-03-30'); //this is a Date object

if (date > new Date()) { //Date object comparison
   //[...]
}
// or
if (date.getTime() > Date.now()) { //unix timestamp (integer) comparison
   //[...]
}

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.