Page 1 of 1

Time Counter

Posted: Wed Aug 29, 2007 9:38 pm
by cashflowtips
Can anyone teach me how to do the time counter?

Situation : user enter the number of days he want, php code will save the number into database and from it, the number will decrease each day until it finally reach the time set by the user?

Thanks for any help!

Posted: Wed Aug 29, 2007 9:44 pm
by s.dot
Usage of strtotime() and/or mktime() along with time() should provide you with suitable timestamps to do calculations with.

Posted: Thu Aug 30, 2007 2:02 am
by xpgeek
If you using DB to store time, then you don't need to use php to change time.
You can use date and time function of DB.
For mysql date and time functions is here

Re: Time Counter

Posted: Thu Aug 30, 2007 6:56 pm
by califdon
cashflowtips wrote:Can anyone teach me how to do the time counter?

Situation : user enter the number of days he want, php code will save the number into database and from it, the number will decrease each day until it finally reach the time set by the user?

Thanks for any help!
There's an apparent inconsistency in your question. Once you store the number in a database, do you expect it to change every day, all by itself?????? You need to think through your problem.

Posted: Thu Aug 30, 2007 9:18 pm
by tecktalkcm0391

Code: Select all

// have a form that posts whatever information and use it in one of the following examples

    // example 1
           $user_time = mktime(0, 0, 0, 12, 32, 1997);  //create user time..
           // format mktime ( [$hour [, $minute [, $second [, $month [, $day [, $year]]]]]] );

    // example 2
          $user_time = time() + ($days * 24 * 60 *60); // what ever you add to time() has to be in seconds, so we are converting days to seconds
                                              // example: 7 days; 24 hours; 60 mins; 60secs = 604800 seconds

//insert that into the database

Code: Select all

//----
// to do the time countdown 

$current_time = time(); // get current time;

// retrieve user time

$timeleft = $user_time -$current_time; 

echo floor($timeleft / 24 / 60 / 60); //this SHOULD output the hours because we are converting the time from seconds to hours and rounding down (that is what floor does)...


//then just change it a bit to get the  mins and seconds