jquery - How to get first date and last date of month view -
for first instance, question looks duplicate not!
i trying find first , last date of given month in calendar.(shown in attached image yellow highlighted)
example: in attached image
input : month july
result :
first date:28th june 2015 last date: 8th august 2015
i tried below code
var days = ['sunday','monday','tuesday','wednesday','thursday','friday','saturday'], months = ['jan','feb','mar','apr','may','jun','jul','aug','sept','oct','nov','dec']; date.prototype.getmonthname = function() { return months[this.getmonth()]; }; date.prototype.getdayname = function() { return days[this.getday()]; }; date.prototype.getpreviousdate = function(beforedays) { if (!days) { beforedays = 0 } return new date(new date().setdate(this.getdate() - beforedays)); } var date = new date(); var firstday = new date(date.getfullyear(), date.getmonth(), 1); var lastday = new date(date.getfullyear(), date.getmonth() + 1, 0); var startdate = firstday.getpreviousdate(3);//hard coded alert(startdate) // //this gives 28th june 2015
jsfiddle works, here have hard coded value "3", want dynamically.
help appreciated.
solution
getfirstvisibleday: function(date){ var firstday = 0; var firstvisibleday = new date(date.getfullyear(), date.getmonth(), 0, date.gethours(), date.getminutes(), date.getseconds(), date.getmilliseconds()); while (firstvisibleday.getday() != firstday) { kendo.date.settime(firstvisibleday, -1 * 86400000); } return firstvisibleday; },
Comments
Post a Comment