Skip to content

Instantly share code, notes, and snippets.

@heyitsnovi
Created May 18, 2020 04:55
Show Gist options
  • Save heyitsnovi/2fb3493fd30cc72f4edb4f62d31b06d0 to your computer and use it in GitHub Desktop.
Save heyitsnovi/2fb3493fd30cc72f4edb4f62d31b06d0 to your computer and use it in GitHub Desktop.
Example of subtracting 2 times
<?php
$hourly_rate = 2.5;
$startTime = new DateTime("2020-05-14 08:00:00");
$endTime = new DateTime("2020-05-14 17:00:00");
$duration = $startTime->diff($endTime); //$duration is a DateInterval object
$worked_hours = (int)$duration->format("%H");
echo $worked_hours * 2.5;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment