Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari/Webkit: Invalid Date for input date format YYYY-MM-DD h:i:s #73

Open
scazzy opened this issue Aug 28, 2017 · 11 comments
Open

Safari/Webkit: Invalid Date for input date format YYYY-MM-DD h:i:s #73

scazzy opened this issue Aug 28, 2017 · 11 comments

Comments

@scazzy
Copy link

scazzy commented Aug 28, 2017

I receive an Invalid date error for a properly valid date param mentioned in title. It's not UTC but it's a valid date on Safari Webkit.

Works fine on chrome and firefox.
Doesn't work on Chrome, Safari - iOS, Safari - MacOS

@scazzy scazzy changed the title Invalid Date for input date format YYYY-MM-DD h:i:s Safari/Webkit: Invalid Date for input date format YYYY-MM-DD h:i:s Aug 28, 2017
@alextouzel
Copy link

alextouzel commented Jan 27, 2018

Same here, this error is thrown only on Internet Explorer (11.1) :

if (isNaN(date)) {
    throw TypeError('Invalid date');
}

and then IE can't even interpret it and throws this error in my console :

SCRIPT5022 You included a throw statement in your code, but it was not enclosed within a try block, or there was no associated catch block to trap the error.

@alextouzel
Copy link

alextouzel commented Jan 27, 2018

Don't know if that can fix your problem, but I fixed mine using the Date.parse() method in javascript :

dateFormat(Date.parse("2018-01-27 18:30:47"), "d mmmm yyyy");

@yuconora
Copy link

yuconora commented Mar 7, 2018

In Safari/Webkit you can try YYYY/MM/DD instead YYYY-MM-DD

@Lelith
Copy link

Lelith commented Nov 12, 2018

another solution i found on stackoverflow was using moment

var startDate = moment('2015-07-06 08:00', 'YYYY-MM-DD HH:mm').toDate();

@patelakash317
Copy link

Try this:
https://stackoverflow.com/a/50033029

@birendra2016
Copy link

Don't know if that can fix your problem, but I fixed mine using the Data.parse() method in javascript :

dateFormat(Date.parse("2018-01-27 18:30:47"), "d mmmm yyyy");
This is wrong, what ever date will be passed, it will take always current date.

@ghost
Copy link

ghost commented Apr 8, 2020

Try this :
var date = "2012-12-31".split("-");
var your_date = new Date(date[0], date[1]-1, date[2]);

@andrmoel
Copy link

another solution i found on stackoverflow was using moment

var startDate = moment('2015-07-06 08:00', 'YYYY-MM-DD HH:mm').toDate();

Highly overloaded library. Works but I do not recommend to use moment when you want a light app.

@rmaximoc
Copy link

rmaximoc commented Sep 15, 2020

Someone is looking to this one?
I get the same error here

@hamed-farag
Copy link

i got the same error too
image

and fixed by @alextouzel solution

Don't know if that can fix your problem, but I fixed mine using the Date.parse() method in javascript :

dateFormat(Date.parse("2018-01-27 18:30:47"), "d mmmm yyyy");

@osymo
Copy link

osymo commented Feb 26, 2022

Screen Shot 2022-02-26 at 19 42 05

Using Date constructor on a string date with format YYYY-MM-DD h:i:s, I got similar error with safari while the same code was working well with chrome.

The solution for me was to transform a format like this YYYY-MM-DD h:i:s to a format like this YYYY-MM-DDTh:i:s (notice the capital T between the date part and the time part).

I dit the transformation with a code like this:

let d = '2021-09-12 00:00:00';

d = d.replace(' ', 'T')

and now when I do : new Date(d) everything works well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants