Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 338
Mudassar Avatar asked Dec 11 '25 22:12

Mudassar


1 Answers

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

console.log(moment().date()) //  Return 5
like image 93
xplo4d Avatar answered Dec 13 '25 12:12

xplo4d



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!