JavaScript Problem

1. Member
Join Date
Dec 1969
Posts
45

## JavaScript Problem

Hi<BR><BR>I am doing a validation for Leap Year. Here I am checking if the month is 2 and if year/4 != parseInt(year) then its not a leap year otherwise its a leap year. But now if the year is 1900, its not a leap year. But according to my checks it becomes the leap year.<BR><BR>What i am thinking is, if year contains two zeros(&#039;00&#039;) then i can check for remaining two digits devide by 4 or not.<BR>e.g. if year is again 1900 then it contains two zeros. So i can take 19 out od that and check if its divisible by 4 or not. (Ultimate thing i want to check is number divisible by 400..) But are there any functions where i can use Right(year,2) or Left(year,2). If Yes how to use them.<BR><BR>Can anyone suggest me what else i need to include and how to work this correctly.<BR><BR>Thx<BR>Ani.

2. Member
Join Date
Dec 1969
Posts
30

## RE: JavaScript Problem

Try this function:<BR><BR>function fGetDaysInMonth(iMonth, iYear) {<BR>var dPrevDate = new Date(iYear, iMonth, 0);<BR>return dPrevDate.getDate();<BR>}<BR>If you pass the value of iMonth and iYear, which u know<BR>It returns Days in that month. This is foolproof and I have tested it.

3. Member
Join Date
Dec 1969
Posts
45

## RE: JavaScript Problem

Thx.<BR>This is not what I want. I need to check for Leap Year after user entry. So that for the month Feb, if its a not leap year then system should not allow days to enter more than 28.(Consider a date of Birth for example)<BR><BR>Otherwise just let me know if i have a value 1900 and i want to separate it in 19 and 00 then how you will do it?<BR><BR>Thanx<BR>Ani.

4. Member
Join Date
Dec 1969
Posts
84

## RE: JavaScript Problem

Remo&#039;s script does just that.<BR><BR>If your user enters his/her date of birth in a text-box.You just need to enter the iMonth as 2 and iYear as the Year part of the users date of birth.This will return 28 if it is not a Leap Year and 29 if it is.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•