Hofmann
09-29-2004, 07:08 PM
Hey, im making a calendar component for å page and it works pretty well except for when I change the month. It then mess up everything and I really dont know wich month its suppose to display. Im using some date functions from the library at this site and they work pretty good when I just feed them with a exact date, but now I want to change the month with som buttons. This is the code for month change:
this.dateObj = new Date()
this.currentMonth = this.dateObj.getMonth()
this.currentYear = this.dateObj.getFullYear()
this._parent.currentMonth -= 1
this._parent.dateObj.setDate(this._parent.currentY ear,this._parent.currentMonth-1)
this._parent.dateStart = this._parent.dateObj.getMonthStartDay()
this._parent.dateEnd = this._parent.dateObj.getDaysInMonth()
trace(this._parent.dateObj.getDate())
Date.prototype.getDaysInMonth = function() {
var temp = this
for (var i=28; i<=(this.dateObj.getMonth()!=1? 31:29); i++)
{
temp.setDate(i);
if (i==temp.getDate()) { var days=i; }
}
return days;
}
// <num> = Starting day of the week (0-6)
Date.prototype.getMonthStartDay = function()
{
var tdate = this
return tdate.getDay();
}
The trace returns 31 as the date of nearly every month, except for sometimes its the first in the month, wtf???
currentMonth is a variable I made at Init wich is just an Int. Is there another way for me to change the date without setting the date like I do?
Sorry bout the noob questions, but I thought this would be pretty straight forward...
Let me know if u need any more code.
this.dateObj = new Date()
this.currentMonth = this.dateObj.getMonth()
this.currentYear = this.dateObj.getFullYear()
this._parent.currentMonth -= 1
this._parent.dateObj.setDate(this._parent.currentY ear,this._parent.currentMonth-1)
this._parent.dateStart = this._parent.dateObj.getMonthStartDay()
this._parent.dateEnd = this._parent.dateObj.getDaysInMonth()
trace(this._parent.dateObj.getDate())
Date.prototype.getDaysInMonth = function() {
var temp = this
for (var i=28; i<=(this.dateObj.getMonth()!=1? 31:29); i++)
{
temp.setDate(i);
if (i==temp.getDate()) { var days=i; }
}
return days;
}
// <num> = Starting day of the week (0-6)
Date.prototype.getMonthStartDay = function()
{
var tdate = this
return tdate.getDay();
}
The trace returns 31 as the date of nearly every month, except for sometimes its the first in the month, wtf???
currentMonth is a variable I made at Init wich is just an Int. Is there another way for me to change the date without setting the date like I do?
Sorry bout the noob questions, but I thought this would be pretty straight forward...
Let me know if u need any more code.