Im having troubles with code for project Leap Years-help please

  • 🙂

  • We need more info. What are you trying to do with Leap Years? Is your project named "Leap Years" or are you trying to calculate what the next N leap years will be or something else? What kinds of problems are you having. What have you tried so far?

  • j

  • ksullivan (3/10/2008)


    We need more info. What are you trying to do with Leap Years? Is your project named "Leap Years" or are you trying to calculate what the next N leap years will be or something else? What kinds of problems are you having. What have you tried so far?

    so any ideas how to fix it? if can help me with code let me know please.Thanks

  • This looks like homework and is not a sql server issue, so I am only posting pseudocode.

    make a new date var as Jan 1 + the year part of startDate

    begin loop

    if mod 4 = 0

    if mod 100 = 0

    if mod 400 = 0

    yes

    loop

    end if

    no

    loop

    end if

    yes

    end if

    add 1 year to the Jan 1 var

    end loop

  • The definition of leap years changed many times and leap years didn't always exist. In fact, depending on which country you're talking about, leap year definitions were different for a long time. And, you better get real familiar with the year 1752 to do this all and why 1752 made 01/01/1753 such an important date for SQL Server. There's also several different calendar shifts as folks finally figured out how long and actual year was and they didn't all happen in 1752.

    Dare I even mention "Leap Seconds"? 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • After you pick a more reasonable starting data than 10000BC, give some serious thought to using something other than a loop to evaluate which years are leap years -- you would be better off to just calculate every 4th year with minor adjustments for the 100/400 year exceptions. (And remember that the date calculation functions in SQL Server account for leap years already.)

  • My biggest curiosity - why are we discussing VisualBasic homework in a SQL forum? The homework pretty much shoots any ability to leverage SQL Server, and I'm pretty sure your teacher would ding you for doing so.

    That being said - good luck with it!

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • I hope you do not intend to store BC dates in SQL Server 2000.

    In SQL Server 2000, the allowable range for the datetime type is from January 1, 1753 through December 31, 9999.

    Sort of reminds me of a quizz show on TV where a contestant was asked in which years the war of independance occurred. The contestant was totally clueless and when told what it was, justified her ignorance by saying "I was not even born in those years".

    Sacrificing history -- anything before 1753 is irrelevant as compared to the essential need to make provisions now to accommodate year 9999.

    Maybe that got fixed in 2005...

  • Question must have been - which years for the 'American' war of independence?

    There have been other WoI. My Citizens of the USA amigos or CUSAs for short plural (pronounced cussers). 😉

    Hiding under a desk from SSIS Implemenation Work :crazy:

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply