problem with time script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • _Skare_Krow_

    #1

    problem with time script

    In my script main_date = 2007-01-24
    and I'm getting this as my result for the due date 2007 04 06
    what am I doing wrong here?

    Aaron

    <?
    $maint_date = date(' Y m d', $maint_date);
    if ($maint_interv = "monthly")
    {
    $interval = //mktime(0, 0, 0, date("m")+ 1, 1, date("Y"));
    "1 week";
    }
    $interval = strtotime($inte rval);
    $due_date = $maint_date + $interval;
    echo date(' Y m d', $due_date);
    echo "<br>$interval" ;
    ?>
  • mds

    #2
    Re: problem with time script

    _Skare_Krow_ wrote:
    $due_date = $maint_date + $interval;
    this adds int to string.

    Comment

    • _Skare_Krow_

      #3
      Re: problem with time script

      mds wrote:
      _Skare_Krow_ wrote:
      >
      >$due_date = $maint_date + $interval;
      >
      this adds int to string.
      ok so how do I add something to a date?

      Comment

      • Hendri Kurniawan

        #4
        Re: problem with time script

        _Skare_Krow_ wrote:
        In my script main_date = 2007-01-24
        and I'm getting this as my result for the due date 2007 04 06
        what am I doing wrong here?
        >
        Aaron
        >
        <?
        $maint_date = date(' Y m d', $maint_date);
        if ($maint_interv = "monthly")
        {
        $interval = //mktime(0, 0, 0, date("m")+ 1, 1, date("Y"));
        "1 week";
        }
        $interval = strtotime($inte rval);
        $due_date = $maint_date + $interval;
        echo date(' Y m d', $due_date);
        echo "<br>$interval" ;
        ?>
        do not put this line on:
        $maint_date = date(' Y m d', $maint_date);
        instead if $maint_date is a string "2007-01-24", do this:
        $maint_date = strtotime($main t_date);

        remove the reference to interval.
        How to calculate interval:
        "monthly": interval is 60 sec * 60 minutes * 24 hours * 30 days
        so that is: $interval = 60 * 60 * 24 * 30;
        assuming 1 month is 30 days of course.

        So $due_date is simply $maint_date + $interval

        Comment

        • Toby A Inkster

          #5
          Re: problem with time script

          _Skare_Krow_ wrote:
          $interval = strtotime("1 week");
          This doesn't do what you think it does. strtotime() doesn't output
          intervals; it outputs timestamps; here is it returning the timestamp for
          the date one week from today.

          You need to calculate the interval by yourself:

          $interval = 7 * 24 * 60 * 60; // seconds in one week

          --
          Toby A Inkster BSc (Hons) ARCS
          Contact Me ~ http://tobyinkster.co.uk/contact
          Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

          * = I'm getting there!

          Comment

          • Kimmo Laine

            #6
            Re: problem with time script

            "_Skare_Kro w_" <petra2201@gmai l.comwrote in message
            news:lYKdncsBc8 xjtnPYnZ2dnUVZ_ hWdnZ2d@sysmatr ix.net...
            mds wrote:
            >_Skare_Krow_ wrote:
            >>
            >>$due_date = $maint_date + $interval;
            >>
            >this adds int to string.
            >
            ok so how do I add something to a date?
            $original_date = '2007-03-07';
            echo date('Y-m-d', strtotime('+1we ek', strtotime($orig inal_date)));

            OR

            $original_date = '2007-03-07';
            list($Y,$m,$d) = explode('-',$original_dat e);
            echo date('Y-m-d', mktime(12,0,0,$ m,$d+7,$Y));

            --
            "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
            http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
            spam@outolempi. net | rot13(xvzzb@bhg byrzcv.arg)


            Comment

            • _Skare_Krow_

              #7
              Re: problem with time script

              Hendri Kurniawan wrote:
              _Skare_Krow_ wrote:
              >In my script main_date = 2007-01-24
              >and I'm getting this as my result for the due date 2007 04 06
              >what am I doing wrong here?
              >>
              >Aaron
              >>
              ><?
              >$maint_date = date(' Y m d', $maint_date);
              >if ($maint_interv = "monthly")
              >{
              >$interval = //mktime(0, 0, 0, date("m")+ 1, 1, date("Y"));
              >"1 week";
              >}
              >$interval = strtotime($inte rval);
              >$due_date = $maint_date + $interval;
              >echo date(' Y m d', $due_date);
              >echo "<br>$interval" ;
              >?>
              >
              do not put this line on:
              $maint_date = date(' Y m d', $maint_date);
              instead if $maint_date is a string "2007-01-24", do this:
              $maint_date = strtotime($main t_date);
              >
              remove the reference to interval.
              How to calculate interval:
              "monthly": interval is 60 sec * 60 minutes * 24 hours * 30 days
              so that is: $interval = 60 * 60 * 24 * 30;
              assuming 1 month is 30 days of course.
              >
              So $due_date is simply $maint_date + $interval
              Many thanks I can now nest the "intervals" and go on... strtotime just
              isn't working quite the way I thought it would.

              Aaron

              Comment

              Working...