Number of days in 1/1/2000

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • el_roachmeister@yahoo.com

    Number of days in 1/1/2000

    I am looking for a script that can report the number of days since
    2000. It should handle leap years but I am not worried about accuracy
    to the hour/minute or seconds. I am writing a calendar program and need
    a reference point to base all my dates from. So I picked 1/1/2000.

  • bradb

    #2
    Re: Number of days in 1/1/2000

    There are many calendar functions built into PHP

    I would suggest you look into those, as you may find a much better way
    to do what you want.

    Comment

    • Oli Filth

      #3
      Re: Number of days in 1/1/2000

      el_roachmeister @yahoo.com said the following on 11/11/2005 16:24:[color=blue]
      > I am looking for a script that can report the number of days since
      > 2000. It should handle leap years but I am not worried about accuracy
      > to the hour/minute or seconds. I am writing a calendar program and need
      > a reference point to base all my dates from. So I picked 1/1/2000.
      >[/color]



      Then divide by 86400 ( = 24 * 60 * 60)

      --
      Oli

      Comment

      • Erwin Moller

        #4
        Re: Number of days in 1/1/2000

        el_roachmeister @yahoo.com wrote:
        [color=blue]
        > I am looking for a script that can report the number of days since
        > 2000. It should handle leap years but I am not worried about accuracy
        > to the hour/minute or seconds. I am writing a calendar program and need
        > a reference point to base all my dates from. So I picked 1/1/2000.[/color]

        Hi,

        I think the most simple way is using Unix timestamps

        (from http://nl2.php.net/manual/en/function.time.php)

        *************** *************** *
        time() -> Return current Unix timestamp
        Returns the current time measured in the number of seconds since the Unix
        Epoch (January 1 1970 00:00:00 GMT).
        *************** *************** *

        So code something like this:
        1) Get the Unixtime for 1/1/2000 (you can calculate that only one time, and
        use the number from then on hardcoded if you want)

        2) Get the Unixtime for now: use the function time()

        3) get the difference

        4) divide it by the number of seconds in a day.

        You will always get a 'dayfraction' this way, and have to do some rounding.

        How you do the rounding is up to your taste of course.
        (Eg, if the difference between now and 1/1/2000 is X and a half day, do you
        want to work with X or X+1 ?)

        Hope this helps. :-)

        Good luck!

        Regards,
        Erwin Moller

        Comment

        • Peter Fox

          #5
          Re: Number of days in 1/1/2000

          Following on from bradb's message. . .[color=blue]
          >There are many calendar functions built into PHP
          >http://us3.php.net/manual/en/ref.calendar.php
          >I would suggest you look into those, as you may find a much better way
          >to do what you want.
          >[/color]

          Come off it! You'll be telling us next there is an extensive manual
          available in various handy formats for instant download from the web
          next.

          Eee I remember when I were a lad when we had nobut beads and bits of
          coloured glass and feathers handed down from father to son. And all
          we'd got to code with was pneumatic riveter. All by the light of a
          guttering candle stuck in a heap of mud - in hexadecimal of course.
          There we were, fighting in the trenches by day, programming using with
          broken matchsticks and blood soaked bandages during the night - all on
          5d a day. Lah-de-dah computer geeks of today don't know they're even
          born. WE didn't even have computers - but we still managed to program
          even though we had to sell our own snot to pay for the fish bones to
          feed the owls.

          --
          PETER FOX Not the same since the e-commerce business came to a .
          peterfox@eminen t.demon.co.uk.n ot.this.bit.no. html
          2 Tees Close, Witham, Essex.
          Gravity beer in Essex <http://www.eminent.dem on.co.uk>

          Comment

          • JDS

            #6
            Re: Number of days in 1/1/2000

            On Fri, 11 Nov 2005 17:06:55 +0000, Peter Fox wrote:
            [color=blue]
            > WE didn't even have computers - but we still managed to program
            > even though we had to sell our own snot to pay for the fish bones to
            > feed the owls.[/color]

            Too much coffee today? Not enough? MP festival on the telly?

            --
            JDS | jeffrey@example .invalid
            | http://www.newtnotes.com
            DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

            Comment

            • el_roachmeister@yahoo.com

              #7
              Re: Number of days in 1/1/2000

              thanks for the replies, here's what I did. Is there any situation where
              this would not give the right answer?


              function get_current_day () {

              $then = mktime ( 0 , 0, 0, 1,1,'00');
              $now = time();

              $days = ($now - $then ) / 86400 - 1;

              return (int) $days;

              } // end function

              Comment

              • Oli Filth

                #8
                Re: Number of days in 1/1/2000

                el_roachmeister @yahoo.com said the following on 11/11/2005 18:56:[color=blue]
                > thanks for the replies, here's what I did. Is there any situation where
                > this would not give the right answer?
                >
                >
                > function get_current_day () {
                >
                > $then = mktime ( 0 , 0, 0, 1,1,'00');
                > $now = time();
                >
                > $days = ($now - $then ) / 86400 - 1;
                >
                > return (int) $days;
                >
                > } // end function
                >[/color]

                Not sure about the -1. If today was the 2nd Jan 2000, for instance, then
                your answer would be 0, but you presumably would want 1.

                --
                Oli

                Comment

                • Toby Inkster

                  #9
                  Re: Number of days in 1/1/2000

                  el_roachmeister wrote:
                  [color=blue]
                  > I am looking for a script that can report the number of days since
                  > 2000.[/color]

                  <?php
                  $start = strtotime("1 Jan 2000");
                  $finish = strtotime("now" );
                  $diff = $finish - $start;
                  $days = (int)($diff / 86400);
                  print $days;
                  ?>

                  --
                  Toby A Inkster BSc (Hons) ARCS
                  Contact Me ~ http://tobyinkster.co.uk/contact

                  Comment

                  Working...