Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding two time values of similar formats using php

Tags:

php

datetime

i have two time values as give below

$time  = 06:58:00;
$time2 = 00:40:00;

I am doing this for calculating the appointments and available time for a particular user so i tried in this way

$max_date=abs(strtotime($time) + strtotime($time2));

but it is returning $max_date =2673452280 any suggestions pls

like image 719
SureshKumar Vegesna Avatar asked May 11 '12 18:05

SureshKumar Vegesna


People also ask

How can I compare two time in php?

Use date_diff() Function to Get Time Difference in Minutes in PHP. We will use the built-in function date_diff() to get time difference in minutes. For this, we need a start date and an end date. We will calculate their time difference in minutes using the date_diff() function.

How will you get the difference between 2 DateTime values in seconds in php?

1 Answer. Show activity on this post. $timeFirst = strtotime('2011-05-12 18:20:20'); $timeSecond = strtotime('2011-05-13 18:20:20'); $differenceInSeconds = $timeSecond - $timeFirst; You will then be able to use the seconds to find minutes, hours, days, etc.

How can I get minutes between two dates in php?

We will be using the built-in function date_diff() to get the time difference in minutes. For this, we will be needed a start date and end date to calculate their time difference in minutes using the date_diff() function. Syntax: date_diff($datetime1, $datetime2);


1 Answers

this code sample would take hour in $time and add the hour in $time2 to it

for example: time=06:58:00, time2=00:40:00, result = 07:38:00

$time = "06:58:00";
$time2 = "00:40:00";

$secs = strtotime($time2)-strtotime("00:00:00");
$result = date("H:i:s",strtotime($time)+$secs);
like image 87
Yaron U. Avatar answered Oct 06 '22 04:10

Yaron U.