0

I have an array with dates like so:

Nov 01 2015 22: +0
Nov 01 2015 23: +0
Nov 02 2015 00: +0
Nov 02 2015 01: +0

This is exactly the format I'm getting from the server and I have no control on it. Is it possible to refer all of these as dates? For example, I would like to get only those from November 2.

3
  • 6
    how about new Date('Nov 10 2015 22: +0'); ? Commented Nov 2, 2015 at 19:36
  • 1
    if you want the timestamp, Date.parse( 'Nov 01 2015 22: +0' ); Commented Nov 2, 2015 at 19:38
  • This is working great. I think I'll get along from here, thank you! Commented Nov 2, 2015 at 19:39

1 Answer 1

1

You can compare each element of your array with a reference date and populate another array with the right dates.

var dates = ['Nov 01 2015 22: +0', 'Nov 01 2015 23: +0', 'Nov 02 2015 00: +0', 'Nov 02 2015 01: +0'];

var referenceDate = Date.parse('Nov 02 2015 00: +0');

var yourDates = [];

function custom(element, index, array) {
    if ( Date.parse(element) >= referenceDate)
    {
    	yourDates.push(element);
    }
}

dates.forEach(custom);

console.log(yourDates);

// THIS WILL OUTPUT:
//
// ["Nov 02 2015 00: +0", "Nov 02 2015 01: +0"]

DEMO: http://jsfiddle.net/w6vz34bb/

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.