• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Leap year issue

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am facing issue in javascript, like dates validation in leap year. we can give the data rages from any month to any month(let's us say like Eg1: 1/April/1999 to 30/march/2000 and there is a chance of giving the dates like Eg2: 1/Jan/1998 to 1/Jan/1999).
If the given dates not fallen in a leap year, then it is working fine. Otherwise it is not working. So can you suggest me how i can implement the logic?

Thanks in Advance..
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would help if you showed your code that fails.

Eric
 
Krish Yeruva
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,
Thanks for your reply.
1) And the code that I used to check whether the year is having 365 days or not

function dtCompare(dt1,dt2) {
var bdate=Date.parse(dt1);
var edate=Date.parse(dt2);
if((edate-bdate)>31449600000) {
return true;
}
else {
return false;
}
}

From this, how i can find the leap year from the given dates?
Could you please help me regarding this?
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can't you decided based on bdate,cdate values. I don't understand why are you using 365 days in code.
 
Krish Yeruva
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Srinivas,
Thanks for your reply.
I am just checking whether the given dates are in year range or not.
Just leave that piece of code.Could you show me the code to find whether the given dates are in leap year or not?

Thanks in Advance
 
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

Isn't it easier to find out if any of the years entered are a leap year? Then use some logic?



Sean
 
Krish Yeruva
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sean,
The user can enter the dates like this:
Eg1: 1/April/1999 to 30/march/2000
and there is a chance of giving the dates like Eg2: 1/Jan/1998 to 1/Jan/1999

In this case, how we can find out the leap year?

Thanks in Advance
 
Sean Clark
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you need to give more of an explanation of why you need to know it is a leap year?

Are you counting the days between the 2 or is there another reason?

Sean
 
Eric Pascarello
author
Posts: 15385
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.bing.com/search?q=javascript+leap+year

Eric
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic