Page 1 of 1

Adding time to a timestamp

Posted: Thu Jul 15, 2004 1:39 am
by tores
From my mysql-database i fetch these two values:
1. "2004-07-31 23:00:00"
and
2. "02:00:00"

Now I do strtotime on the 1st, and want to add the 2nd. This should result in "2004-08-01 01:00:00"

Anyone know how this could be done in a simple and correct way?

regards tores

Posted: Thu Jul 15, 2004 1:41 am
by feyd
have you tried strtotime() on the second time?

Posted: Thu Jul 15, 2004 1:45 am
by tores
yes, but then i get "2004-07-31 23:00:02"...

Posted: Thu Jul 15, 2004 1:46 am
by feyd
you could use explode() and mktime(), or concat the time with "Jan 01, 1969" then strtotime()

Posted: Thu Jul 15, 2004 2:03 am
by tores
Okey... Now it's almost right. I concatenate so i get
"1970-01-01 02:00:00". When i do strtotime on this i get 3600... But that's the equal of ONE hour, not two... Maybe i have to convert into seconds myself??

Posted: Thu Jul 15, 2004 2:22 am
by tores
Converted "02:00:00" to secondes using explode... Problem solved