11-23-2008, 01:56 AM
|
#7 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
I created this class to modify the dates using the strtotime function. Use it if you wish!
php Code:
class Date_Calculate { private $m_iFromTimestamp; public function __call($szCall, $aArgs) { if (preg_match('~^to(Minus|Plus)(\d+)(.+)$~i', $szCall, $aMatches)) { $szOperator = $aMatches[ 1] == 'Minus' ? '-' : '+'; $iTimestamp = ! empty($this-> m_iFromTimestamp) ? $this-> m_iFromTimestamp : time(); return date($aArgs[ 0], strtotime($szOperator . $aMatches[ 2] . ' ' . $aMatches[ 3], $iTimestamp)); } throw new Exception ('Invalid date to syntax specified'); } public function from ($iTimestamp) { if (! is_integer($iTimestamp)) { $iTimestamp = strtotime($iTimestamp); } $this-> m_iFromTimestamp = $iTimestamp; return $this; }}$pDate = new Date_Calculate (); echo $pDate-> from(time())-> toMinus4Days('jS M Y'); echo $pDate-> toPlus5Years('jS M Y');
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|