javascript Date interpretation issues

i have end dates that are stored in the database as: February 15, 2018 10:9:29

one is created from edge browser, one from chrome and one from FF. all of them are stored with the same string.
but all these browsers interpret the date differently. i attach the console images:
edge interpret all of them.
chrome and FF see the one that was created with edge as Invalid Date
also, FF interpret the date differently than chrome.

the aim is to delete the record if the date and time has past. so i have this:
let today = new Date();
console.log('today: ',today);
          data.forEach((data) => {

            if( new Date(data.enddate) < today  ){
              //delete automatically hangouts which are past due date
              console.log('in the past: ',new Date(data.enddate));
              console.log('not in the past: ',new Date(data.enddate));


Open in new window

the issue is that the deletion obviously does not work with the Invald date.

any idea?
from chromefrom edgefrom FF
Who is Participating?
Julian HansenCommented:
Ah ok, then why not store the time as a timestamp rather than a string - from Firebase perspective it is still a string / number but the format will be common across all browsers.

In JavaScript this would be

var t = new Date().getTime();

Open in new window

Gets the UTC timestamp (in miliseconds) of the local date.

To compare to the current date
let today = new Date().getTime();;
if (today < data.enddate) {
   // now just compare on the UTC ms value

Open in new window

If you want to use as a Date() object then you do this
var d = new Date(0);
// proceed as per normal

Open in new window

Julian HansenCommented:
When you say
i have end dates that are stored in the database as: February 15, 2018 10:9:29
Do you mean your dates are stored as text in the database?

If so why are you doing that and not using a database datetime format.

Also take a look at the moment.js library - it has everything you could possibly need for date / time functions.
derridaAuthor Commented:
it is firebase real time database. as far as i know it is stored as string.
do i need moment for just checking if the end date has passed?
derridaAuthor Commented:
sorry , only came to this now. as always great detailed answers from Julian Hansen
Julian HansenCommented:
You are welcome and thank you.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.