4 Replies Latest reply on Nov 28, 2008 6:07 AM by Newsgroup_User

    date calculation

    9thReg Level 1
      Hello all,

      I'm trying to set up a dues page for a client where a database entry for the date the last dues were paid is displayed. Then, automatically calculate a future date from that database entry to display when the next dues are to be paid.

      Here is what I've got so far:

      Your last Membership Dues were paid on
      <?php
      $date = new DateTime($row_Database['row']);
      echo $date->format("d-F-Y");
      ?> .

          Your next Membership Dues will be payable on

      <?php
      $date = new DateTime($row_Database['row']);
      $date->modify("+365 day");
      echo $date->format("d-F-Y");
      ?> .

      however on the first $date = new DateTime($row_Database['row']); line, I get the following error on the server:

      Fatal error: Call to a member function on a non-object in /.../dues.php on line 148

      When I play around with it, it seems like I've got problems with every line there. I got these lines from a tutorial, and it worked perfectly on my local server, but when I put it on the clients server, it stopped working. Anyone have any ideas as to what I did wrong and how to fix this? Thanks.
        • 1. Re: date calculation
          Level 7
          9thReg wrote:
          > however on the first $date = new DateTime($row_Database['row']); line, I get
          > the following error on the server:
          >
          > Fatal error: Call to a member function on a non-object in /.../dues.php on
          > line 148

          You say it works locally, but not on the remote server. That almost
          certainly means the remote server is running PHP 4. The DateTime class
          requires a minimum of PHP 5.1.

          --
          David Powers, Adobe Community Expert
          Author, "The Essential Guide to Dreamweaver CS4",
          "PHP Solutions" & "PHP Object-Oriented Solutions"
          http://foundationphp.com/
          • 2. Re: date calculation
            Level 7
            David Powers wrote:
            > You say it works locally, but not on the remote server. That almost
            > certainly means the remote server is running PHP 4. The DateTime class
            > requires a minimum of PHP 5.1.

            By the way, you can rewrite that code in PHP 4 like this:

            Your last Membership Dues were paid on
            <?php
            $date = strtotime($row_Database['row']);
            echo date("d-F-Y", $date);
            ?>
            Your next Membership Dues will be payable on
            <?php
            $renew = strtotime("+365 day", $date);
            echo date("d-F-Y", $renew);
            ?>

            --
            David Powers, Adobe Community Expert
            Author, "The Essential Guide to Dreamweaver CS4",
            "PHP Solutions" & "PHP Object-Oriented Solutions"
            http://foundationphp.com/
            • 3. Re: date calculation
              9thReg Level 1
              oh my gosh, thank you so much. That worked perfectly.
              • 4. Re: date calculation
                Level 7
                9thReg wrote:
                > oh my gosh, thank you so much. That worked perfectly.

                Glad to have helped. However, you should tell your client to update to a
                PHP 5 server. All official support for PHP 4 came to an end on 8 August
                2008.

                --
                David Powers, Adobe Community Expert
                Author, "The Essential Guide to Dreamweaver CS4",
                "PHP Solutions" & "PHP Object-Oriented Solutions"
                http://foundationphp.com/