Results 1 to 2 of 2

Thread: Active time.

  1. #1
    Join Date
    Sep 2009
    Posts
    3

    Red face Unanswered: Active time.

    How do I make time running when I'm offline. For example user inserted time into database 01:30:00. And after one hour and thirty minutes time will be 00:00:00. So how do we do that? I think you can't do it with plain SQL. We need to use another programming language, but which one? You can't do it with PHP it works only when you are online.

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Quote Originally Posted by kostik7
    How do I make time running when I'm offline.
    You need to store a real time rather than just the value '01:30:00' so first create a table to store the time:
    Code:
    create table tb1( t datetime );
    Then calculate and store the real time the countdown should finish at:
    Code:
    insert tb1 values ( from_unixtime(
                        unix_timestamp( now() ) +
                        time_to_sec( '00:01:30' )  ) );
    Now just keep doing the following select to show the countdown:
    Code:
    select sec_to_time( unix_timestamp( t ) - (unix_timestamp( now() ) ) )
              as countdown
    from tb1;
    Which should show something like:
    Code:
    +-----------+
    | countdown |
    +-----------+
    |  00:03:00 |
    +-----------+
    
    +-----------+
    | countdown |
    +-----------+
    |  00:02:59 |
    +-----------+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •