note 50059 deleted from function.date by derick

From: Date: Sun, 11 Jun 2006 11:32:33 +0000
Subject: note 50059 deleted from function.date by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-114221@lists.php.net to get a copy of this message
Note Submitter: erik[at]phpcastle.com ---- A little script that gives an array with periodes: Example: 2005-01-01, 2005-01-02, 2005-01-03, 2005-01-04 will be 2005-01-01, 2005-01-04 If you can work by periodes can this save some database space/speed. Code: <?php $previous_date = ""; $periodes = array(); $pointer = 0; foreach ($_POST['data'] as $key=>$value){ if (!empty($previous_date)) if (floor(abs(strtotime($previous_date) - strtotime($value))/86400) == 1){ $periodes[$pointer+1] = $value; } else{ $pointer +=2; $periodes[$pointer] = $value; $periodes[$pointer+1] = $value; } else { $periodes[$pointer] = $value; $periodes[$pointer+1] = $value; } $previous_date = $value; } ?> The $periodes array will look like this: [start_date],[end_date](,[start_date],[end_date]) Hope this code can help someone :) cheers

« previous php.notes (#114221) next »