Help With PHP and timestamp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dusen
    Confirmed User
    • Aug 2002
    • 2251

    #1

    Help With PHP and timestamp

    I set this up:

    $time1=time();

    Later On,

    $time2=time();

    if I:

    echo $time1 -> 1109145600
    echo $time2 -> 1109201240

    But if I

    echo($time2 - $time1) -> -1109145600

    Why? Why is it not 55640?

    Can Anyone help?
    Penis Pill Sponsor List and Reviews:
    http://www.pillsponsors.com
  • azguy
    Confirmed User
    • Nov 2004
    • 5167

    #2
    Can't be.

    But try echo((int)$time2 - (int)$time1);

    Comment

    • MikeXAMO
      Confirmed User
      • Mar 2002
      • 660

      #3
      you sure your echo statement is exactly as shown? It should print 55640, unless you misspelled your variable, or maybe forgot to put brackets around your math statement.

      Try doing:

      Code:
      $time1=time();
      $time2=time();
      $result=$time2-$time1;
      echo $result;
      That should guarantee you the result you want. You shouldn't have to use typecasting (int) if you assigned your variables using the time() function, it will return an integer.
      Xamo Entertainment
      Xamo.com | EZSets.com

      ICQ: 9439118 MSN: mikeb [at] xamo.com Tollfree: 800-544-XAMO
      XXX CMS - Designed by Adult Webmasters, for Adult Webmasters.

      Comment

      • richard
        Confirmed User
        • Feb 2001
        • 543

        #4
        My guess is that you've made a type on the echo?

        ie PHP is calculating "0-$time1"

        Comment

        • MikeXAMO
          Confirmed User
          • Mar 2002
          • 660

          #5
          by the way, if you are timing your application, use microtime() as it is more precise (milliseconds).
          Xamo Entertainment
          Xamo.com | EZSets.com

          ICQ: 9439118 MSN: mikeb [at] xamo.com Tollfree: 800-544-XAMO
          XXX CMS - Designed by Adult Webmasters, for Adult Webmasters.

          Comment

          • Dusen
            Confirmed User
            • Aug 2002
            • 2251

            #6
            Damn, I should be in bed. That's exactly what it was doing.

            0-$time1

            mistyped var.

            Thanks for the help guys.
            Penis Pill Sponsor List and Reviews:
            http://www.pillsponsors.com

            Comment

            • azguy
              Confirmed User
              • Nov 2004
              • 5167

              #7
              hehe

              Comment

              Working...