How to get the number of days in a month
P粉354948724
P粉354948724 2023-08-25 13:55:10
0
2
609
<p>I made a countdown timer and need to get the number of days in a month and subtract the number of days that have passed (eg: 30 days in September minus 8 days - today's date). Now I need to manually enter: </p> <pre class="brush:php;toolbar:false;">const end = new Date(2021, 8, 30, 13, 0,12, 12);</pre></p>
P粉354948724
P粉354948724

reply all(2)
P粉916553895

You can use the following code to get the number of days in a month:

const getDays = (year, month) => new Date(year, month, 0).getDate()

const days = getDays(2021, 8)
console.log(days)
P粉792673958

Number of days remaining in this month

var currentDate = new Date();
var currentYear = currentDate.getFullYear();
var currentMonth = currentDate.getMonth();

var currentMonthLastDate = (new Date(currentYear, currentMonth, 0)).getDate();

var daysLeftInMonth = currentMonthLastDate - currentDate.getDate();

console.log(daysLeftInMonth);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template