COUNTDOWN

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

Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Yeah, I realised the default thing as soon as I posted it.

But when you say length, do you mean how long the date value should be?

If I want to have years, months, days, hours, minutes, and seconds
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

ok, I just checked and you don't need the length so just do something like this:

Code: Select all

ALTER TABLE myTable ADD COLUMN myTimeField time
that will only work for time values (hour:minute:second). In other words, if you want to stamp the date as well you're going to need to use datetime (year-month-day hour:minute:second).
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

And how do I recall it?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Code: Select all

select myTimeField from myTable where username = 'bob'
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Ok, I get that but, I need to add an amount of seconds or minutes onto the time, but if I just add them like this:

$row[‘time’] + 10

It won't work.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Code: Select all

echo date("g:i:s",strtotime($row['time']."+10 seconds"));
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Can you explain each part individually please?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

echo date("g:i:s",strtotime($row['time']."+10 seconds"));
date() I already told you to research...go do that:

for the example I posted:
date() takes two arguments, the first is the format you want the date/time formated in (in this case g=hours w/o leading zeros i=minutes with leading zeros s=seconds with leading zeros

the second argument is the variable you want formated, in this case I used another function strtotime() which can do a whole bunch of really cool stuff (Burrito pauses for a moment to give props to whomever created strtotime) for this example I just took your var from the result set and added 10 seconds to it.

go look at those two links for more info...
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Thanks Burrito

So... Will this work:

Code: Select all

$create = CREATE TABLE stats (oc time NOT NULL,PRIMARY KEY (oc))&quote;;
Then to insert the value:

Code: Select all

mysql_query(&quote;INSERT INTO stats (oc) VALUES ('&quote;strtotime(&quote;+120 seconds&quote;), &quote;\n&quote;;&quote;')&quote;;
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

no, the time fields in MySQL don't work with the unix times, they need the format I posted earlier (hours:minutes:seconds)...

use a combination of date() and strtotime() to format the time when you insert it.

that one I'm gonna let you figure out :wink:
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

you gotta play around, make a fake user so it start the timer (ie puts the now() time into the database) then query out what the time looks like. if your useing datetime you will have somthing like YYYY-MM-DD HH-MM-SS then use the php function date() to check how much time has passed. its really quite easy just try some diffrent stuff and play around and im sure you will get it.
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Ok. One last thing. I get the whole time idea but, if I want to add 120 seconds onto the current time. Is the time stored as a number?

So if the time was 204506 (20:45:06) could I...

$time = 204506
$addedtime = time + 200

:?: 8O
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

have you tried it out?
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

I'm about to
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

good, try all your possible ideas before u repost then reply with a code that you think SHOULD work but dosnt if that happens
Post Reply