How to get Start Date and End Date in Last month using Javascripts.
For an example:
Today - 09/07/2013
I need to get output
Last month start date: 01/06/2013 Last month end date: 30/06/2013
We can use the startOf method to get the first day of the current month. And we can use the endOf method to get the last day of the current month. We call moment to create a Moment object with the current date and time.
Javascript date getMonth() method returns the month in the specified date according to local time. The value returned by getMonth() is an integer between 0 and 11. 0 corresponds to January, 1 to February, and so on.
To get the first day of a month, use the Date() constructor to create a date object, passing it the year, month and 1 for the day as parameters. The Date object will contain the first day of the month.
=EOMONTH(A2, -1) - returns the last day of the month, one month before the date in cell A2. Instead of a cell reference, you can hardcode a date in your EOMONTH formula.
function f()
{
var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth()-1, 1);
var lastDay = new Date(date.getFullYear(), date.getMonth(), 0);
alert(firstDay+"==="+lastDay);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With