Page 2 of 3
Posted: Thu May 19, 2005 12:06 pm
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
Posted: Thu May 19, 2005 12:13 pm
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).
Posted: Thu May 19, 2005 12:18 pm
by Parody
And how do I recall it?
Posted: Thu May 19, 2005 12:24 pm
by Burrito
Code: Select all
select myTimeField from myTable where username = 'bob'
Posted: Thu May 19, 2005 12:26 pm
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.
Posted: Thu May 19, 2005 12:31 pm
by Burrito
Code: Select all
echo date("g:i:s",strtotime($row['time']."+10 seconds"));
Posted: Thu May 19, 2005 12:32 pm
by Parody
Can you explain each part individually please?
Posted: Thu May 19, 2005 12:39 pm
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...
Posted: Thu May 19, 2005 12:49 pm
by Parody
Thanks Burrito
So... Will this work:
Code: Select all
$create = CREATE TABLE stats (oc time NOT NULL,PRIMARY KEY (oc))"e;;
Then to insert the value:
Code: Select all
mysql_query("e;INSERT INTO stats (oc) VALUES ('"e;strtotime("e;+120 seconds"e;), "e;\n"e;;"e;')"e;;
Posted: Thu May 19, 2005 12:54 pm
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

Posted: Thu May 19, 2005 1:34 pm
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.
Posted: Thu May 19, 2005 1:47 pm
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

Posted: Thu May 19, 2005 1:48 pm
by shiznatix
have you tried it out?
Posted: Thu May 19, 2005 1:50 pm
by Parody
I'm about to
Posted: Thu May 19, 2005 1:51 pm
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