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.
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.
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);
try this:
date = new Date(2016, 5, 1);
lastdate = new Date(date - 1);
console.log(lastdate)
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();
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);
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);