-1

I have only month e.g : 'May'

from this i want to get start date and last date of 'May' month using java-script.

Thank you.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
SAGAR MANE
  • 685
  • 2
  • 8
  • 23
  • 2
    The start date is always "1" (e.g. "May 1") – Buddy Jun 29 '16 at 07:23
  • It already answered on stackoverflow [here](http://stackoverflow.com/questions/13571700/get-first-and-last-date-of-current-month-with-javascript-or-jquery) – Smit Mehta Jun 29 '16 at 07:27
  • 2
    Possible duplicate of [Calculate last day of month in javascript](http://stackoverflow.com/questions/222309/calculate-last-day-of-month-in-javascript) – Dave Jun 29 '16 at 07:42

5 Answers5

2

The first date of any month would be 1. As far as the last date is concerned you can use moveToLastDayOfMonth

Moves the date to the last day of the month.

or you can use this way:

var month = 4; 
var d = new Date(2016, month + 1, 0);
alert(d); 
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0

try this:

date = new Date(2016, 5, 1);
lastdate = new Date(date - 1);
console.log(lastdate)
Mahendra Kulkarni
  • 1,437
  • 2
  • 26
  • 35
0

start date always will be 1 and, for last date you can try this,

var date = new Date();
var lastDate = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
Lalit Goswami
  • 798
  • 1
  • 8
  • 21
0

Thank you for your respond.

I found this answer.

var month = 'MAY'
var a = '1-'+month+'-2015';
        var date = new Date(a);
        var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
        var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
        console.log(firstDay);
        console.log(lastDay);
SAGAR MANE
  • 685
  • 2
  • 8
  • 23
0

I created months array for check month value for JS standard date.Then get date format Date(year,month,day) as you want

var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
var month = "May";
for(var i in months){
    if(months[i] == month){
        month = i;
    }
}
var s = new Date(2016, month, 1);
var e = new Date(2016, ++month, 0);
console.log(s+"\n"+e);
Jack jdeoel
  • 4,554
  • 5
  • 26
  • 52