Last active
January 29, 2016 06:24
-
-
Save sarfraznawaz2005/dbd591991767c2eb6b5a to your computer and use it in GitHub Desktop.
hours till today
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| date_default_timezone_set('Asia/Karachi'); | |
| ################################################################# | |
| $leaves = 0; // edit this if needed | |
| ################################################################# | |
| $hours = 8; | |
| $workdays = array(); | |
| $month = date('n'); // Month ID, 1 through to 12. | |
| $year = date('Y'); // Year in 4 digit 2009 format. | |
| $startDate = new DateTime(date('Y-m-1')); | |
| $datetime2 = new DateTime(date('Y-m-d')); | |
| $interval = $startDate->diff($datetime2); | |
| $day_count = $interval->days; // days from 1st of month to today | |
| //loop through all days | |
| for ($i = 1; $i <= $day_count; $i++) { | |
| $date = $year.'/'.$month.'/'.$i; //format date | |
| $get_name = date('l', strtotime($date)); //get week day | |
| $day_name = substr($get_name, 0, 3); // Trim day name to 3 chars | |
| //if not a weekend add day to array | |
| if ($day_name != 'Sun' && $day_name != 'Sat') { | |
| $workdays[] = $i; | |
| } | |
| } | |
| $total_work_days = count($workdays) - $leaves; | |
| $total_hours = (count($workdays) - $leaves) * $hours; | |
| echo "<strong>" . date('F') . ' - ' . $year . "</strong><hr>" | |
| . "Total Working Hours = <strong>$total_hours</strong><br>" | |
| . "Total Working Days = <strong>$total_work_days</strong><br>" | |
| . "Total Days = <strong>$day_count</strong><br>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment