Adding minutes 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
assgar
Forum Commoner
Posts: 46
Joined: Fri Apr 20, 2007 9:00 pm

Adding minutes to a timestamp

Post by assgar »

Hi


How can I add 15 minutes to the previous event time (timestamp) to get the next event time.
Note: This event time is not in a table.

Straight forward adding the two values will probly not provide the correct result.

I can get the correct time with Mysql addtime($time, $duration) but that
is only good if the if info is in a table.

Thanks

Code: Select all

<?php
$time = "09:00:00";//timestamp hh:mm:ss
$duration = 00:15:00;//enent duration hh:mm:ss


$next_time = $event_time + $event_duration;
?>
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

This would be usefull :

strtotime()
There are 10 types of people in this world, those who understand binary and those who don't
assgar
Forum Commoner
Posts: 46
Joined: Fri Apr 20, 2007 9:00 pm

Solution

Post by assgar »

Hi

Thanks for the suggestion.
This is the final code that solved the problem

Code: Select all

<?
	$event_time = 09:00:00
	$event_length = 15;
	
	$timestamp = strtotime("$event_time");
	$etime = strtotime("+$event_length minutes", $timestamp);
	$next_time = date('H:i:s', $etime);
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

General Discussion's description specifically states: This forum is not for asking programming related questions.
Post Reply