TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-22-2008, 11:05 PM   #1 (permalink)
The Wanderer
 
paulOr's Avatar
 
Join Date: Nov 2007
Location: Edinburgh
Posts: 21
Thanks: 1
paulOr is on a distinguished road
Default date() + 30 days = xxx

Ok so iv been trying to figure out how to do this little thing:

i have todays date: 22 November 2008 and i want to add 30 days onto it, and end up with another date, which would be 22 December 2008.

so like:
PHP Code:
date('j F Y') + 30 new_date('j F Y'
Is there a easy way of doing this? Im so stuck!
__________________
paulOr.net
paulOr is offline  
Reply With Quote
Old 11-22-2008, 11:24 PM   #2 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

PHP Code:
$d mktime(0,0,0,$month,$day,$year);
$end_date date(”Y m d”,strtotime(+2 days”,$d));

//To add days to current date
date(’Y-m-d’strtotime(+2 days”)); 
codefreek is offline  
Reply With Quote
Old 11-22-2008, 11:26 PM   #3 (permalink)
The Wanderer
 
paulOr's Avatar
 
Join Date: Nov 2007
Location: Edinburgh
Posts: 21
Thanks: 1
paulOr is on a distinguished road
Default

well, the date is just coming from date() but new_date will be stored in mysql :P
__________________
paulOr.net
paulOr is offline  
Reply With Quote
Old 11-22-2008, 11:29 PM   #4 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by codefreek View Post
is it for mysql ? then i know :P
Doesn't matter? xD

Just use it like this:
php Code:
$endDate = date("D F d Y", strtotime("+30 days"));
__________________
Tanax is offline  
Reply With Quote
Old 11-22-2008, 11:31 PM   #5 (permalink)
The Wanderer
 
paulOr's Avatar
 
Join Date: Nov 2007
Location: Edinburgh
Posts: 21
Thanks: 1
paulOr is on a distinguished road
Default

PHP Code:
date('j F Y'strtotime('+30 days')); 
got it :)
__________________
paulOr.net
paulOr is offline  
Reply With Quote
Old 11-22-2008, 11:35 PM   #6 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

i was thinking on something else sorry but i posted my way but tanax was faster oh well ;)
codefreek is offline  
Reply With Quote
Old 11-23-2008, 01:56 AM   #7 (permalink)
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)
Old 11-23-2008, 07:27 AM   #8 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

looks great, Wildhoney :D
thanks for sharing will probably learn something from it will,
look at it some more later..
codefreek is offline  
Reply With Quote
Old 11-23-2008, 09:25 AM   #9 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

Damns some sweet logic Adam :)
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:33 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design