0
var current_date = '2015-10-21 16:08:30';
var event_start_date = '2015-10-27 09:30:00';
var event_end_date =  '2015-10-28 18:30:00';

if(new Date(current_date) > new Date(event_end_date)){
    //Event has been ended
} else if((new Date(current_date) > new Date(event_start_date)) && (new Date(current_date) < new Date(event_end_date))){
   //Event is running. Event will close event_end_date
} else {
   //Event not started yet. Event will start event_start_date
}

Above JavaScript condition not working.

What is wrong with me?

Notes :- Mozilla firefox above code not working. Please check JSFiDDLE

Chinmay235
  • 3,236
  • 8
  • 62
  • 93

2 Answers2

0

First convert the to javascript date format. for eg.

var current_date = new Date('2015-10-21 16:08:30'); //works in chrome but not in firefox

Then your conditions will work.

Please follow this: new Date() is working in Chrome but not Firefox

Apparently Mozilla is not very much flexible. Check there documentation: Date Object

Community
  • 1
  • 1
xangy
  • 1,185
  • 1
  • 8
  • 19
0

Browser support for parsing string to Date object is inconsistent. There is no specification on formats, so this is why it works on Chrome but not on Firefox.

See this link for a table of supported formats on each browser

I personally use moment.js framework to manipulate Dates on JavaScript, it's easy to use and has a consistent API that works on most browsers.

var current_date = '2015-10-21 16:08:30';

var momentDate = moment('2015-10-21 16:08:30', 'YYYY-MM-DD HH:mm:ss');
alvarodms
  • 671
  • 5
  • 8