Time/Date conversion year/week -> day/month/year

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #16
    NO sir! Leap year handling is in the code already, otherwise it would not have worked for 2008! The leap year handling is done in the following statements in the code[php]if ($year % 4 == 0)
    for ($i=1; $i<12; $i++)
    $monthtab[$i]++;[/php]
    and you don't want to worry about 400-year cycle because the previous one was 1600 and the next one is 2400. And the strtotime routine does not go that far (just until 2032(?).

    Ronald

    Comment

    • TheServant
      Recognized Expert Top Contributor
      • Feb 2008
      • 1168

      #17
      Good point. I forgot the dates don't go back that far! And I didn't realize that it only goes upto 2032?! That's no good. Means that we will have to recode with a new date function :P

      Ron, what does the line: if ($year % 4 == 0) mean?

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #18
        Originally posted by TheServant
        Ron, what does the line: if ($year % 4 == 0) mean?
        This uses the modulo operator. The modulo operation finds the remainder of division of one number by another.

        Given two numbers, $year (the dividend) and 4 (the divisor), a modulo 4 is the remainder, on division of $year by 4. For instance, the expression "2008 mod 4" would evaluate to 0, while "2007 mod 4" would evaluate to 3.

        So when the modulo 4 of year is zero, it is a leap year.

        Ronald

        Comment

        • TheServant
          Recognized Expert Top Contributor
          • Feb 2008
          • 1168

          #19
          Originally posted by ronverdonk
          This uses the modulo operator. The modulo operation finds the remainder of division of one number by another.

          Given two numbers, $year (the dividend) and 4 (the divisor), a modulo 4 is the remainder, on division of $year by 4. For instance, the expression "2008 mod 4" would evaluate to 0, while "2007 mod 4" would evaluate to 3.

          So when the modulo 4 of year is zero, it is a leap year.

          Ronald
          So:
          [PHP]5 %4 = 0.25
          4 %4 = 0
          26 %6 = 0.333
          30 %6 = 0[/PHP]Just making sure I understand, because this is useful!

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #20
            No sir, the modulus is the remainder of the division, e.g. 4 mod 3 = 1 because when you divide 4 by 3 the remainder is 1. So:
            Code:
            5 % 4 = 1
            4 % 4 = 0
            26 % 6 = 2
            30 % 6 = 0
            E.g. n mod 2 is often used to 'flip' between 2-entry indices or determine if a number is even or uneven, i.e. 1%2 = 1, 8%2 = 0, 133%2=1, 8490%2=0, etc.

            Ronald

            Comment

            • TheServant
              Recognized Expert Top Contributor
              • Feb 2008
              • 1168

              #21
              I understand. Thanks for that lesson.

              Comment

              • ronverdonk
                Recognized Expert Specialist
                • Jul 2006
                • 4259

                #22
                Originally posted by TheServant
                I understand. Thanks for that lesson.
                You are most welcome.

                Ronald

                Comment

                Working...