How to convert a string date (December 18, 2022) to YYYY/MM/DD format? (Couldn’t find a solution), and if statement passing that isn’t supposed to [duplicate]

My current method is first of all inefficient.
I’m trying to change this to YYYY/MM/DD format.

date = new Date('January 23, 2021');

Is supposed to return ‘2021-01-23’

Where I’m stuck at in my code is that this if statement keeps passing when its supposed to fail.

if (var.toString().includes('-')) {

} else if (var.toString().includes('January')){
    return var;
}

I didn’t fill in the code but the issue is that the program passes the .includes(‘-‘) part of the if statement and I don’t know why it does.