note 103466 modified in function.date by danbrown

From: Date: Thu, 14 Apr 2011 16:51:37 +0000
Subject: note 103466 modified in function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178850@lists.php.net to get a copy of this message
a simple method to work out future dates from a given one. <?php /** * Handles a date in the format YYYYMMDD. * * Doesn't take a genius to modify it to use some other format. * We provide either of the following units: * 'h' -> 'hour', 'i' -> 'minute', 's' -> 'second', * 'm' -> 'month','d' -> 'day' , 'y' -> 'year' */ public static function getNextDate($date, $amount, $unit='d'){ $dividers = array(' ', ':', '_', '-', '/', '|'); $date = str_replace($dividers, '', $date); $unit = strtolower($unit); list($y, $m, $d) = array(substr($date, 0, 4), substr($date, 4, 2), substr($date, 6)); list($h, $i, $s) = array(1, 0, 0); $x = substr($unit, 0, 1); $$x += $amount; return date('Ymd', mktime($h, $i, $s, $m, $d, $y)); } ?> --was-- a simple method to work out future dates from a given one. /** * Handles a date in the format YYYYMMDD. * * Doesn't take a genius to modify it to use some other format. * We provide either of the following units: * 'h' -> 'hour', 'i' -> 'minute', 's' -> 'second', * 'm' -> 'month','d' -> 'day' , 'y' -> 'year' */ public static function getNextDate($date, $amount, $unit='d'){ $dividers = array(' ', ':', '_', '-', '/', '|'); $date = str_replace($dividers, '', $date); $unit = strtolower($unit); list($y, $m, $d) = array(substr($date, 0, 4), substr($date, 4, 2), substr($date, 6)); list($h, $i, $s) = array(1, 0, 0); $x = substr($unit, 0, 1); $$x += $amount; return date('Ymd', mktime($h, $i, $s, $m, $d, $y)); } http://php.net/manual/en/function.date.php

« previous php.notes (#178850) next »