This question already has answers here:
How to calculate the difference between two dates using PHP?
(34 answers)
Closed 6 years ago.
I want to count how many hours, minutes and seconds between two dates.
For example: Date 1: 01-01-1990 12:00 and 01-02-1990 13:00
Now, how many hours, minutes, and second from date 1 to date 2 using php?
just use strtotime() on your dates to their timestampz . and then subtract them to have the difference in the number of seconds. it's easy to convert from there
Related
This question already has answers here:
Convert Days to Year,Month,Day Format
(2 answers)
How to calculate the difference between two dates using PHP?
(34 answers)
Closed 2 years ago.
1st method: I've got x days and I want to convert it to weeks and month via php. For example 24 days:
3 weeks 3 days
or 45 days:
that's where my problem starts. How can I know that 45 days is how many month including month differentials?
2nd method: I've got two dates, for example 2020-05-13 and 2020-07-14. Can I calculate month, weeks, and days somehow from these?
I don't have any code since I don't even know how to start it.
This question already has answers here:
Calculate difference between two dates (number of days)?
(17 answers)
Finding the number of days between two dates
(34 answers)
Closed 8 years ago.
I want to calculate days between 2 month.1 date is set that is 01-03-2014 and second date will be given by user.This may be any date for example 14-05-2014.Now i want to calculate days between these 2 dates?
Thanks
You can use DateTime for this, and do a simply calculation. See DateTime:diff
<?php
$start= new DateTime('14-05-2014');
$end= new DateTime('01-03-2014');
$interval = $start->diff($end);
echo $interval->format("%a total days"); //Output: 74 total days
https://eval.in/236630
This question already has answers here:
How to calculate the difference between two dates using PHP?
(34 answers)
Closed 9 years ago.
how to calculate the minute difference for 2 values:-
strtotime("-15 minutes");
strtotime("now");
i have used below code:-
$diff = floor(strtotime("now") - strtotime("-15 minutes")/3600 );
but it gives 5 days of difference.
please guide me where I am wrong.
First of all you are getting hour diff with division to 3600. 15 minutes evaluates to 0 when floored. Also you are only dividing the second variable not the first with those brackets.
this should work:
$diff=floor((strtotime("now") - strtotime("-15 minutes"))/60);
echo $diff;// outputs 15
This question already has answers here:
Calculate time elapsed in php - spans over 24 hours
(2 answers)
Closed 9 years ago.
I have been searching for a while now regarding on how to format hours in php that will show 000:00:00 instead of 00:00:00.
I need this to calculate the duration of records with start and end Date with a datetime data type in mysql.
The problem with my current format ('H:m:s') is it only count 24 hours and when the duration goes higher than that, it will show 01:00:00 instead of 25:00:00.
Try TIMEDIFF() function in MySQL
Example:
SELECT TIMEDIFF('2008-12-31 23:59:59.000001',
'2008-12-30 01:01:01.000002');
-> '46:58:57.999999'
This question already has answers here:
Calculate number of hours between 2 dates in PHP
(17 answers)
Closed 9 years ago.
Is there any recommendation of datetime calculation?
I have been going toward UNIX timestamp and diff calculation method
but both of it don't really provide a better way to complete my task.
Here is the sample of datetime I have.
2013-09-07 21:12
I wish to calculate the duration between the 2 datetime.
Lastly display the total of minutes duration for the 2 datetime.
Most of the calculation work to display for year, months, days, hours, minutes, seconds.
I need some method to find out the duration between 2 times and convert the duration into total of minutes.
Anyone?
Use function mktime to get the UNIX timestamp of the two dates, then take the bigger one and subtract the smaller one. You'll get another value, if you divide that value by 60, you'll get how many minutes are inbetween the two dates.