I have a date field in ISO format like this:
2017-06-06T00:00:00
I'm looking for a way to find if the date string above represents Saturday or Sunday. I've read some post and all of them have a Date object format date and not an ISO date.
I really appreciate your help
Asked
Active
Viewed 3,137 times
2

RamAlx
- 6,976
- 23
- 58
- 106
-
I thought calling `Date(string)` would try to parse it using the ISO format first... is that not the case? – Jon Skeet Aug 10 '17 at 09:07
-
I've tried to parse it but it didn't return me the correct date – RamAlx Aug 10 '17 at 09:08
-
So include that information in the question - show what you've tried and what went wrong. – Jon Skeet Aug 10 '17 at 09:10
2 Answers
4
The Date
constructor accepts (a simplified version of) ISO date strings:
const date = new Date('2017-06-06T00:00:00');
const day = date.getDay();
console.log(day); // 2 = Tuesday

Robby Cornelissen
- 91,784
- 22
- 134
- 156
2
const date = new Date('2017-06-06T00:00:00');
const day = date.getDay();
const days = ["Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat"];
console.log(days[day]);

Jetal mali
- 43
- 5
-
1Please read [answer] and [edit] your answer to contain an explanation as to why this code would actually solve the problem at hand. Always remember that you're not only solving the problem, but are also educating the OP and any future readers of this post – chrslg Jan 29 '23 at 00:20