Time Counter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cashflowtips
Forum Newbie
Posts: 22
Joined: Tue Jul 31, 2007 11:06 pm

Time Counter

Post 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!
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

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.
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Time Counter

Post 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.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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
Post Reply