WDI-SEA / project-4-issues

Open an issue to receive help on project 4 issues
0 stars 0 forks source link

Date comparison not working #31

Closed jyang1003 closed 2 years ago

jyang1003 commented 2 years ago

What stack are you using?

(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)

MERN

What's the problem you're trying to solve?

Trying to solve a date comparison for my filter

Post any code you think might be relevant (one fenced block per file)

    let today = new Date(),
    date = `${today.getFullYear()}-${(today.getMonth()+1)}-${today.getDate()}`

    let thisDayNutrition = allNutrition.filter(object, index => object.date == today)

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

no error message but the filter isn't working

What is your best guess as to the source of the problem?

the format of the dates are different so the filter will never === true.

What things have you already tried to solve the problem?

different filter arguments and different date constructors

tkolsrud commented 2 years ago

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date

It looks like you can set the format of the date when you call the method