I have a method:
function setToMonday( date ) {
var day = date.getDay() || 7;
if( day !== 1 )
date.setHours(-24 * (day - 1));
return date;
}
I need to call the split method on the returned date. But split is not recognised: gg.split is not a function
var gg = setToMonday(new Date().toString());
var week1 = gg.split('T')[0];
console.log(week1);
I've seen on other Q's to use toString()But it doesn't seem to be working for me.
asked Dec 1, 2020 at 15:07
flutter
6,83610 gold badges52 silver badges93 bronze badges
1 Answer 1
You're putting toString in the wrong place. You don't want to convert the date you're passing in to a string, you want to convert the date you're getting out to a string:
var gg = setToMonday(new Date());
var week1 = gg.toString().split('T')[0];
console.log(week1);
answered Dec 1, 2020 at 15:09
Aplet123
35.8k1 gold badge41 silver badges66 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
setToMondaynot throw, when you are callingdate.getDayon a string? I am confused.toString()on the return ofsetToMonday(), not as the input tosetToMonday()