PDA

View Full Version : Need HELP!! (displaing dates in a calendar format)


hogtied
10-12-2002, 05:22 PM
Hey, I'm having trouble in figuring out how to display the dates in calendar format. Please keep in mind that there will be an option to go back or forward months.

Here's the JavaScript:

function load()
{
var today = new Date()
var year = today.getYear()
var numMonth = today.getMonth()
var numDay = today.getDay()
var numDate = today.getDate()
var arMonth = new Array("January", "Feburary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
var arMonthLen = new Array("31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31")

if (year%4)
{
arMonthLen[1] = "29"
}

var firstDay = numDay

for (var i=1; i < numDate; i++)
{
firstDay--
if (firstDay < 0)
{
firstDay = 6
}
}

Year.innerHTML = '<font size="4"><b>' + year + '</b></font>'
Month.innerHTML = '<font size="4"><b>' + arMonth[numMonth] + '</b></font>'
}

if you have any suggestion, even if it is to make this more effient please post your comments.

Thanks
Hogtied

mordred
10-12-2002, 06:33 PM
Perhaps you make your question more clear, or point to the parts of your code you don't understand at the moment...including your expectations what these parts should do and why they fail to deliver (and possibly any error messages they generate). Remember, the more descriptive you are, the better the answers you get.

One thing I can tell you:

if (year%4)

This will not do what you expect. It will be true on all years *except* the leap year, because the % operator returns the rest of the division or 0 - the latter which causes your if statement to be wrong. Try

if (year % 4 == 0)

or

if ( !(year % 4) )

Garadon
10-12-2002, 07:31 PM
a little useless info :D

It is leap year if.

1:the year is dividable by 4
2:it is not leap year if the year is dividable by 100
3:it is leap year if the year is dividable by 400

hogtied
10-12-2002, 09:30 PM
Ok sorry about that. I'll have to figure out how to explain it better.

All im trying to do is display the information in a calender format.

The code hasn't been written. Just the calculate the dates have be written.

Don't know how to go about this.