[SOLVED] Adding time to a timestamp

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
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Adding time to a timestamp

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

have you tried strtotime() on the second time?
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Post by tores »

yes, but then i get "2004-07-31 23:00:02"...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you could use explode() and mktime(), or concat the time with "Jan 01, 1969" then strtotime()
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Post 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??
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Post by tores »

Converted "02:00:00" to secondes using explode... Problem solved
Post Reply