Get the count of passed days from start of month till today using moment.js

Mudassar045 :

Does any body know, any method provided by moment.js to get the days count that are passed till today (include current day too) for the current month.

Let say current days is: 05-03-2020 (dd-mm-yyyy)

let count_of_days = moment().getPassedDays()

console.log(count_of_days) // output 5

Some Solutions I tried:

1-

let count_of_days = moment().days() + 1
console.log(count_of_days) // 5

2-

let count_of_days = parseInt(moment().format("DD")) + 1
console.log(count_of_days) // 5

3-

let start_of_month = moment().startOf("month")

let curr_day_of_month = moment()

let count_of_days = start_of_month.diff(curr_day_of_month, "days") + 1
console.log(count_of_days) // 5
xplo4d :

I think date() function return what you're looking for

console.log(moment().date()) //  Return 5

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=29704&siteId=1