Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Start Date and End Date in Last month using Javascripts? [duplicate]

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

like image 932
laura Avatar asked Jul 09 '13 05:07

laura


People also ask

How do you find the start date and end of the month in moment?

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.

Which method will return the date within a month JavaScript?

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.

How do you get the first date of the month from a date in JavaScript?

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.

How do I find the last date 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.


1 Answers

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);
}  
like image 57
Ganesh Rengarajan Avatar answered Nov 15 '22 00:11

Ganesh Rengarajan