skylabel
asked on
Adding minutes to a datetime
I've got a datetime field in MySQL in which I store a datetime. The field name is commenceDate. To read into PHP this I use the strtotime function :
$commenceDateTime = strtotime( $commenceDate );
Now I want to add an integer to $commenceDate, represented by the variable $duration (in minutes) so I can calculate the $endDateTime. How do I do this?
$commenceDateTime = strtotime( $commenceDate );
Now I want to add an integer to $commenceDate, represented by the variable $duration (in minutes) so I can calculate the $endDateTime. How do I do this?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
My code is:
$commenceDate = $row['commenceDate'];
$commenceDate = strtotime( $commenceDate );
$endDate = date_modify($commenceDate, "+15 minute");
echo date("m-d-Y H:i", $endDate);
I get an error:
date_modify() expects parameter 1 to be DateTime, integer given in ....
$commenceDate = $row['commenceDate'];
$commenceDate = strtotime( $commenceDate );
$endDate = date_modify($commenceDate,
echo date("m-d-Y H:i", $endDate);
I get an error:
date_modify() expects parameter 1 to be DateTime, integer given in ....
ASKER
I'm using PHP 4. Noticed it's a PHP5 function
then even simpler:
$endDate = strtotime("+15 minute", $row['commenceDate']);
$endDate = strtotime("+15 minute", $row['commenceDate']);
ASKER
No error but I dunno why but the dates coming up are wrong
$commenceDate $endDate
10-25-2007 04:30 01-01-1970 00:48
10-13-2007 05:30 01-01-1970 00:48
10-11-2007 05:30 01-01-1970 00:48
Output always is:
01-01-1970 00:48
$commenceDate $endDate
10-25-2007 04:30 01-01-1970 00:48
10-13-2007 05:30 01-01-1970 00:48
10-11-2007 05:30 01-01-1970 00:48
Output always is:
01-01-1970 00:48
Hello skylabel,
You would use $endDate = strtotime("+15 minute", $commenceDateTime);
Regards,
Roonaan
You would use $endDate = strtotime("+15 minute", $commenceDateTime);
Regards,
Roonaan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry youhave to echo the $outputdate variable.
echo "$outputdate is the incremented time in new format <br>";
as the line in the last post
echo "$outputdate is the incremented time in new format <br>";
as the line in the last post
ASKER
i.e., month-date-year Hour:Minute