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!
Time Counter
Moderator: General Moderators
Usage of strtotime() and/or mktime() along with time() should provide you with suitable timestamps to do calculations with.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- xpgeek
- Forum Contributor
- Posts: 146
- Joined: Mon May 22, 2006 1:45 am
- Location: Kyiv, Ukraine
- Contact:
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
You can use date and time function of DB.
For mysql date and time functions is here
Re: Time Counter
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.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!
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
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 databaseCode: 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