I’m doing a bit of support for Barley today and a customer is having an issue sorting some dates in JavaScript. They’d like to compare a few dates on the page and return the date nearest today’s date. The issue I’m seeing (and I’m no JavaScript guru or anything) is that the dates they are trying to compare are in real language. Here is a quick example date:
MONDAY, FEBRUARY 2, 2015 AT 6:30 PM
This doesn’t follow any normal ISO standard, apparently, so JavaScript’s Date Object won’t accept it as a date. I’ve found a few JavaScript libraries, such as Moment, but it doesn’t seem to be able to handle anything outside of ISO 8601 formats.
If you know of a way (and this seems like it should be easy to do and I’m just missing it) please hit me up on Twitter @cdevroe.
Solved! Thanks to Andy Rocco for pointing out that I only needed to remove the “ at “ from the string and boom, instant date. He also pointed out that Moment.js as a parse plugin that further supports more open text formats for date strings. Good to know.
Here is the Code Pen I created for our customer.