Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. finding Day code based on date.

finding Day code based on date.

Scheduled Pinned Locked Moved Algorithms
algorithmstutorialquestion
17 Posts 8 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C chandu004

    Hai friends, Here is my logic to find the day code. if any body can please suggest a better logic, or if any body can validate the logic and find any bugs there, i would apprieciate it. int offset[12]={0,31,59,90,120,151,181,212,243,273,304,334},l=0; if((((curyear%4==0) && (curyear%100!=0)) || (curyear%400==0)) && (curmonth>1)) l=1; daycode=offset[curmonth]+curdate+l; opinions please.

    L Offline
    L Offline
    Luc Pattyn
    wrote on last edited by
    #8

    Why not just use DateTime.DayOfYear?

    Luc Pattyn [Forum Guidelines] [My Articles]


    this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


    C 1 Reply Last reply
    0
    • D dr mobile

      the main important thing how to prove the correctness of ur function

      researche in mobile databases

      C Offline
      C Offline
      chandu004
      wrote on last edited by
      #9

      just supply some valid values to it and see.

      R D 2 Replies Last reply
      0
      • L Luc Pattyn

        Why not just use DateTime.DayOfYear?

        Luc Pattyn [Forum Guidelines] [My Articles]


        this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


        C Offline
        C Offline
        chandu004
        wrote on last edited by
        #10

        of course, but the user will supply date month and year separately. if i had to use CTime class, then, i had to copy these values to that CTime right? but i think even that can be possible. thanks for your suggestion.

        L 1 Reply Last reply
        0
        • C chandu004

          of course, but the user will supply date month and year separately. if i had to use CTime class, then, i had to copy these values to that CTime right? but i think even that can be possible. thanks for your suggestion.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #11

          int d=new DateTime(2007, 10, 26).DayOfYear;

          Luc Pattyn [Forum Guidelines] [My Articles]


          this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


          C 1 Reply Last reply
          0
          • C chandu004

            just supply some valid values to it and see.

            R Offline
            R Offline
            Ray Cassick
            wrote on last edited by
            #12

            I also recomend testing invalid values and testing for proper failures as well. Quite often we just test for success and don't test for failure. Failing in a predictable manner of often times more important than being correct. Correct is always predictable. Failing often times is not.


            My Blog[^]
            FFRF[^]


            C 1 Reply Last reply
            0
            • L Luc Pattyn

              int d=new DateTime(2007, 10, 26).DayOfYear;

              Luc Pattyn [Forum Guidelines] [My Articles]


              this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


              C Offline
              C Offline
              chandu004
              wrote on last edited by
              #13

              thats simply wonderful, thank you.

              -------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.

              1 Reply Last reply
              0
              • R Ray Cassick

                I also recomend testing invalid values and testing for proper failures as well. Quite often we just test for success and don't test for failure. Failing in a predictable manner of often times more important than being correct. Correct is always predictable. Failing often times is not.


                My Blog[^]
                FFRF[^]


                C Offline
                C Offline
                chandu004
                wrote on last edited by
                #14

                this validation logic is implemented before the algorithm in my application.

                1 Reply Last reply
                0
                • C chandu004

                  just supply some valid values to it and see.

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #15

                  chandu004 wrote:

                  just supply some valid values to it and see.

                  Don't let Prof. Knuth know your secret. :rolleyes:


                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  1 Reply Last reply
                  0
                  • C CPallini

                    century years rules (of course if you need to deal with): (1) Century years aren't leap years (though they're divisible by 4). (2) Century years divisible by 400 (as 2000, for instance) are leap years. Maybe you have to further strain your brain. :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                    D Offline
                    D Offline
                    Dan Neely
                    wrote on last edited by
                    #16

                    The Gregorian calender doesn't have any leapyear exception rules for above 400. IF they did, IIRC the next toggle points would have been 2000 and 10,000. Instead we're adding single leap seconds as needed at new years to keep everything in sync.

                    -- If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.

                    L 1 Reply Last reply
                    0
                    • D Dan Neely

                      The Gregorian calender doesn't have any leapyear exception rules for above 400. IF they did, IIRC the next toggle points would have been 2000 and 10,000. Instead we're adding single leap seconds as needed at new years to keep everything in sync.

                      -- If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #17

                      dan neely wrote:

                      IIRC the next toggle points would have been 2000 and 10,000

                      I doubt that; Wikipedia[^] gives some arguments for a leapyear correction every 4000 or 8000 years.

                      dan neely wrote:

                      Instead we're adding single leap seconds as needed at new years to keep everything in sync

                      That can not be correct: with a one second correction every year you would need 60 * 60 * 24 = 86400 years to shift time by one day, not quite sufficient. [added] Again Wikipedia[^] explains the purpose of leap seconds.[/added] :) -- modified at 18:06 Thursday 1st November, 2007

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups