Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use the strtotime() function to convert the timestamps into Unix timestamps and then subtract them to get the time difference in seconds. Here's an example:

$timestamp1 = '2020-12-01 08:30:00';
$timestamp2 = '2020-12-01 09:15:30';

$time1 = strtotime($timestamp1);
$time2 = strtotime($timestamp2);
$timeDiff = $time2 - $time1;

echo "Time difference: " . $timeDiff . " seconds";

This will output:

Time difference: 2730 seconds

To convert the time difference into minutes, hours, or days, you can divide it by the appropriate factor:

$minutesDiff = $timeDiff / 60;
$hoursDiff = $timeDiff / (60 * 60);
$daysDiff = $timeDiff / (60 * 60 * 24);

Keep in mind that these calculations are based on the Unix timestamp, which is the number of seconds since January 1, 1970. If your timestamps are in a different format or time zone, you may need to adjust the calculations accordingly.