PDA

View Full Version : UNIX timestamps


Dean C
05-11-2003, 12:36 PM
I worked out thanks to someone here at .org how to put a unix timestamp into a readable format with the date() function :)

Now say if im inserting time() into a field in a table

e.g.


UPDATE timer SET time='".time()."';


How would i adapt that query to add a year to the current time?

Thanks in Advance

- miSt

Dean C
05-11-2003, 12:37 PM
WTF bug in the sql code alert ;)

It was meant to read:

UPDATE timer SET time='"time()'";

- miSt

Xenon
05-11-2003, 01:19 PM
erm. '". isn't a sql query, you are trying to mix up php and mysql so you should use php or code tags :)

updateing timefield to add a year:
UPDATE timer SET time=time+3600*24*356

SiGmA_X
05-14-2003, 12:02 AM
Hang on, time() (http://www.php.net/manual/en/function.time.php) doesn't have a year in it? It says it does, and in practice seems to, because it records the amount of seconds from the Epoch, which would include a year. Right? I think miSt's idea of just using time() (http://www.php.net/manual/en/function.time.php) is correct.

But that's just my 2 cents :)

filburt1
05-14-2003, 12:10 AM
time() returns a date in epochs which implicitly has the year.

Dean C
05-14-2003, 03:40 PM
I had to do this in the end ;)


$DB_site->query("UPDATE secrettable SET secretfield=(time()+31536000) WHERE userid=$userid");


- miSt

SiGmA_X
05-14-2003, 03:54 PM
What does the +3153600 do? Being the time is from the Epoch, it will have year.. I am still unsure why you are adding the extra numbers in :\

Dean C
05-14-2003, 03:59 PM
It simply adds a year to the current timestamp outputted from the time() function :)

- miSt