How can timestamps be used to calculate the total time spent at a client's location in PHP?

To calculate the total time spent at a client's location in PHP using timestamps, you can store the timestamp when the client arrives and the timestamp when the client leaves. Then, you can subtract the arrival timestamp from the departure timestamp to get the total time spent at the location in seconds. You can then convert this time to hours, minutes, and seconds for display.

// Example timestamps
$arrival_timestamp = strtotime('2022-01-01 09:00:00');
$departure_timestamp = strtotime('2022-01-01 12:30:00');

// Calculate total time spent at the location in seconds
$total_time_seconds = $departure_timestamp - $arrival_timestamp;

// Convert total time to hours, minutes, and seconds
$total_time_hours = floor($total_time_seconds / 3600);
$total_time_seconds %= 3600;
$total_time_minutes = floor($total_time_seconds / 60);
$total_time_seconds %= 60;

echo "Total time spent at the location: $total_time_hours hours, $total_time_minutes minutes, $total_time_seconds seconds";