Johnston
Johnston

Reputation: 20874

Moment js Not returning the right day of the week

I am trying to use Momentjs to return the day of the week (ex. "monday" or "mon", doesn't matter as long as it's the name of the day of the week) for the string number that I stored in the db (ex "3"). For some reason I keep getting Monday returned.

var values = ["3", "06:00", "18:00"];
moment().isoWeekday(values[0]).format('ddd');
//returns "Mon"

I've also tried using moment('3','d').format('ddd')
I've also tried using moment().days('3').format('ddd')
Always returns the same day. Usually Sat or Mon.

Upvotes: 1

Views: 4367

Answers (1)

Sgoldy
Sgoldy

Reputation: 796

try

moment().isoWeekday(parseInt(values[0])).format('ddd');

And in general, store the week day as integer and not string:

var values = [3, "06:00", "18:00"];

Upvotes: 6

Related Questions