An easy way to display the first day and the last day of the current month using javascript. The date is an important component of an application. Usually, information system applications require dates to carry out business processes. Moreover, to display a reporting period, it requires an input date. Usually, programmers provide the first day and the last day of the month as the initial date input display. I will share the javascript function to display the first day and the last day of the current month. Check out the following tutorial
Javascript function gets the first day and the last day of the current month
Copy the following code and apply it to your application
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | function firstDateOfMonth(){ var date = new Date(); var y = date.getFullYear(); var m = date.getMonth(); var firstDay = new Date(y, m, 1); return firstDay; } function firstDateOfYearMonth(y,m){ var firstDay = new Date(y, m-1, 1); return firstDay; } function lastDateOfMonth(){ var date = new Date(); var y = date.getFullYear(); var m = date.getMonth(); var lastDay = new Date(y, m + 1, 0); return lastDay; } function lastDateOfYearMonth(y,m){ var lastDay = new Date(y, m, 0); return lastDay; } function format_date(d){ var month = '' + (d.getMonth() + 1); var day = '' + d.getDate(); var year = d.getFullYear(); if(month.length < 2){ month = '0' + month; } if(day.length < 2){ day = '0' + day; } return [day, month, year].join('/'); } |
Please try the following example to apply the function of getting the first and the last day of a particular month javascript
Other Article : How To Load JSON Data From Rest API To Select2 JQuery Plugin
Demo : How to get first and the last day of current month javascript
The format_date(d) is used to change the date format. You can change the format_date function according to your application needs.
In Example How to Format Javascript Date To Mysql Format Date
1 2 3 4 5 6 7 8 9 10 | function format_date(d){ month = '' + (d.getMonth() + 1), day = '' + d.getDate(), year = d.getFullYear(); if (month.length < 2) month = '0' + month; if (day.length < 2) day = '0' + day; return [year, month, day ].join('-'); } |
Thus my short tutorial on how to display the first day and the last day of the month in javascript
Leave a Reply