note 48697 modified in function.gmmktime by danbrown

From: Date: Sun, 20 Jul 2008 03:20:01 +0000
Subject: note 48697 modified in function.gmmktime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142052@lists.php.net to get a copy of this message
Here's a play on turgut85's countDays function. I've found it to be more efficient and it accepts unix timestamps rather than arrays. Thanks for the ideas. <?php function count_days($start, $end) { // Count the days between $start and $end where both $start and $end // are UNIX timestamps // Swap the two values if end is greater than start (to avoid the // loop of death). if ($start < $end) { $t = $start; $start = $end; $end = $t; } // Increment the start time by one day until it is equal to the // end time $days = 0; while ( $start < $end ) { $start = strtotime("+1 days", $start); $days++; } return $days; } ?> --was-- Here's a play on turgut85's countDays function. I've found it to be more efficient and it accepts unix timestamps rather than arrays. Thanks for the ideas. function count_days($start, $end) { // Count the days between $start and $end where both $start and $end // are UNIX timestamps // Swap the two values if end is greater than start (to avoid the // loop of death). if ($start < $end) { $t = $start; $start = $end; $end = $t; } // Increment the start time by one day until it is equal to the // end time $days = 0; while ( $start < $end ) { $start = strtotime("+1 days", $start); $days++; } return $days; } http://php.net/manual/en/function.gmmktime.php

« previous php.notes (#142052) next »