View Single Post
Old 11-23-2008, 01:56 AM   #7 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following 2 Users Say Thank You to Wildhoney For This Useful Post:
codefreek (11-23-2008), Kalle (11-23-2008)