If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Active time.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-05-09, 00:03
kostik7 kostik7 is offline
Registered User
 
Join Date: Sep 2009
Posts: 3
Red face 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.
Reply With Quote
  #2 (permalink)  
Old 11-05-09, 04:38
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
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 |
+-----------+
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On