flutter
flutter

Reputation: 6786

split method doesn't recognise String

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.

Upvotes: 0

Views: 37

Answers (1)

Aplet123
Aplet123

Reputation: 35560

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);

Upvotes: 3

Related Questions