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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-06 17:05:19 +0000
Seen: 14 times
Last updated: Jun 06 '23
How can a HTTP header be inserted in WordPress?
How can data be stored in a data attribute and utilized through Ajax?
How can an array be passed using typo3 flexform xml and itemsProcConfig?
Does JSON encode fail to retrieve data from the database?
Can the GS1 128 barcode decoder in PHP or Jquery be utilized?
How can Xdebug be used in conjunction with VSCode for Laravel on Sail and WSL2?
In PHP, what is the method for finding encrypted data using the "like" operator?
What is the method to pass a variable from PHP back to JavaScript?
Why do PHP variable variables display unexpected behavior when used with arrays?