Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

javascript date-function returns wrong weekday for Sep 1,2017 and later when setDate is used AFTER setMonth and/or setFullYear

more options

FF 48.0.2 Sample Code: Try to enter 1.9.17 which is a friday

<input type="text" onchange="wday(this.value);"> <script> function wday() { var x = wday.arguments[0].split("."); if (x[2].length<4) x[2] += 2000; var y = new Date(); y.setFullYear(x[2]); y.setMonth(x[1]-1); y.setDate(x[0]); var z = new Array("So","Mo","Di","Mi","Do","Fr","Sa"); alert("wrong "+z[y.getDay()]) wday2(wday.arguments) } function wday2() { var x = wday.arguments[0].split("."); if (x[2].length<4) x[2] += 2000; var y = new Date(); y.setDate(x[0]); y.setMonth(x[1]-1); y.setFullYear(x[2]); var z = new Array("So","Mo","Di","Mi","Do","Fr","Sa"); alert("correct "+z[y.getDay()]) } </script>

BTW: Same error with Chrome and Edge.

FF 48.0.2 Sample Code: Try to enter 1.9.17 which is a friday <html> <head></head> <body> <input type="text" onchange="wday(this.value);"> <script> function wday() { var x = wday.arguments[0].split("."); if (x[2].length<4) x[2] += 2000; var y = new Date(); y.setFullYear(x[2]); y.setMonth(x[1]-1); y.setDate(x[0]); var z = new Array("So","Mo","Di","Mi","Do","Fr","Sa"); alert("wrong "+z[y.getDay()]) wday2(wday.arguments) } function wday2() { var x = wday.arguments[0].split("."); if (x[2].length<4) x[2] += 2000; var y = new Date(); y.setDate(x[0]); y.setMonth(x[1]-1); y.setFullYear(x[2]); var z = new Array("So","Mo","Di","Mi","Do","Fr","Sa"); alert("correct "+z[y.getDay()]) } </script> </body> </html> BTW: Same error with Chrome and Edge.

Chosen solution

Reply from StackOverflow: new Date() has the current date as initial value (I was not aware of that fact). That messes up my settings. Setting the day first avoids the problem. My fault. Thanks for the hint.

Read this answer in context 👍 0

All Replies (4)

more options

Since the issue occurs on all browsers, it is likely an issue with your code, not the browser. This forum is used for Firefox specific issues.

Since your issue is not Firefox specific, you would probably have better luck posting your question to Stack Overflow. There are plenty of people that help to fix other peoples' codes, so you should have no trouble getting the help that you need.

Sorry for any inconvenience.

more options

Thank you for the quick response. In fact my favourite browser is FF and when I checked the others I was puzzled about getting the same issue...

I can not imagine that the code is wrong since changing the sequence of 1 statement and returns correct results. And it occurs only for dates Sep 1, 2017 and later. Could be an issue in the javascript engine...

Anyway: I'll post it on StackOverflow.

more options

Chosen Solution

Reply from StackOverflow: new Date() has the current date as initial value (I was not aware of that fact). That messes up my settings. Setting the day first avoids the problem. My fault. Thanks for the hint.

more options

No problem. I find that there are tons of great and friendly people on Stack Overflow that are more than willing to help you solve your programming issues.

If you do have any issues with Firefox in the future, feel free to get in touch with the Mozilla support team again. Thanks.