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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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?
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
derridaAuthor Commented:
sorry , only came to this now. as always great detailed answers from Julian Hansen
Julian HansenCommented:
You are welcome and thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.