0

What can I do to compare these different Date-Types for my filter????

MongDB:

2015-04-29T22:00:00.000Z

Datepicker:

Wed Apr 08 2015 00:00:00 GMT+0200 (CEST)

I have a MEAN Stack and write Data from a form into a MongoDB Database. My database entry looks like this:

dt for Date

enter image description here

I use UI-Bootstrap Datepicker to pick the date and save it in this format:

2015-03-31T22:00:00.000Z

Now I have two other Datepickers to set a range and filter them. But when I choose a date in the Datepickers the format change to:

Wed Apr 08 2015 00:00:00 GMT+0200 (CEST)

and I can't compare these two data in my Filter:

angular.module('reklaApp')
 .filter('dateFilter', function () {
    return function (items, fromDate, toDate) {

    var filtered = [];

    for (var i = 0; i < items.length; i++) {

        var item = items[i];

        if (item.dt > fromDate && item.dt < toDate){
            filtered.push(item);
        }
    }

    return filtered;
  };
});

2 Answers 2

1

Create javascript native Date objects and compare them:

var a = new Date("2015-04-29T22:00:00.000Z")
var b = new Date("Wed Apr 08 2015 00:00:00 GMT+0200 (CEST)")

console.log(a > b) // -> true
Sign up to request clarification or add additional context in comments.

Comments

0

You need to parse and convert both date formats to a date instance. Probably, since you are already using a datepicker, the later dates i.e. from & end dates must be a date instance. So the only thing you have to do is to parse the MongoDB date string.

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.