Time stuff calculating with time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • The1corrupted
    New Member
    • Feb 2007
    • 134

    Time stuff calculating with time

    I need help with this little time function. After thirty minutes, I want an echo to occur...

    [PHP]
    $_SESSION['idlemin']=date(i); //This makes the session update each time the page is refreshed but was defined on log in.
    $minutes=date(i ); //Current
    if ($_SESSION['idlemin']>=$minutes+30 ) {
    echo "Your time is up!";
    }
    [/PHP]

    Now, I know this doesn't work for obvious reasons...
    Say you logged in at 14:49 well, it would have to equal 14:79 to work and well, time isn't calculated that high so I need something that can spill over hours..
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Taking the server time use the strtotime function, e.g.

    [php]echo "30 minutes from now = " . date("H:m:s", strtotime("+30 minutes"));[/php]
    Ronald :cool:

    Comment

    • The1corrupted
      New Member
      • Feb 2007
      • 134

      #3
      Cool! Thanks.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Welcome.

        Ronald :cool:

        Comment

        • The1corrupted
          New Member
          • Feb 2007
          • 134

          #5
          Originally posted by ronverdonk
          Taking the server time use the strtotime function, e.g.

          [php]echo "30 minutes from now = " . date("H:m:s", strtotime("+30 minutes"));[/php]
          Ronald :cool:
          Tiny syntax error though...
          [PHP]date("H:m:s", strtotime("+30 minutes"))[/PHP]
          should be
          [PHP]date("H:i:s", strtotime("+30 minutes"))[/PHP]

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Sorry, my mistake. That's what you get when trying to do it without looking at the manual.

            Ronald :cool:

            Comment

            • The1corrupted
              New Member
              • Feb 2007
              • 134

              #7
              Another quickie on time.. could you compare times?
              [PHP]
              $idletime=$_SES SION['idle'];
              if (date("H:i:s")> =$idletime) {
              echo "<META HTTP-EQUIV='refresh' content='0; url=idleout.php '>";
              } elseif (date("H:i:s")< =$idletime) {
              $idletime=date( "H:i:s", strtotime("+30 minutes"));
              }
              [/PHP]
              And on a different page...
              [PHP]$_SESSION['idle']=date("H:i:s", strtotime("+30 minutes"))[/PHP]

              Comment

              • ronverdonk
                Recognized Expert Specialist
                • Jul 2006
                • 4259

                #8
                Why would you format the timestamp in this case. It would be sufficient to just use the Unix timestamp and calculate and compare with that. The format makes it rather difficult.

                Ronald :cool:

                Comment

                • The1corrupted
                  New Member
                  • Feb 2007
                  • 134

                  #9
                  Do you mean that gigantic interger gotten when you use the $_SERVER['request_time'] function?

                  Comment

                  • ronverdonk
                    Recognized Expert Specialist
                    • Jul 2006
                    • 4259

                    #10
                    It is just the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

                    But yes, that is the time format I mean. In your case the 30 minutes is just 1800 seconds.

                    Ronald :cool:

                    Comment

                    • The1corrupted
                      New Member
                      • Feb 2007
                      • 134

                      #11
                      Actually, I've found what I wrote to work perfectly fine, suprisingly.. Just changed minutes to seconds for the test and it works.

                      Comment

                      • ronverdonk
                        Recognized Expert Specialist
                        • Jul 2006
                        • 4259

                        #12
                        When it works: stick with it.

                        Ronald :cool:

                        Comment

                        Working...