TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   help me figure out this date thing (http://www.talkphp.com/absolute-beginners/3358-help-me-figure-out-date-thing.html)

sarmenhb 09-14-2008 10:03 PM

help me figure out this date thing
 
i created this application where a user signs up for something what i want to do is the second the user signs up the date that is inserted into the db is 3 weeks ahead of the signup date for example.

if i signed up on the application todays date would be 9/14/2008 and the date that is inserted into the database would be 10/5/2008 (which is 3 weeks ahead of the sign up date)

how would this be codded???
thanks

Karl 09-14-2008 10:18 PM

php Code:
$iToday = time();
$iNext = strtotime('+3 weeks', $iToday);

sarmenhb 09-14-2008 10:22 PM

Quote:

Originally Posted by Karl (Post 18376)
php Code:
$iToday = time();
$iNext = strtotime('+3 weeks', $iToday);


thanks, but how do i show that as ##/##/## format?

xenon 09-14-2008 10:31 PM

PHP Code:

echo date('m/d/Y'$iNext); 

Check out the date function on php.net.

ETbyrne 09-15-2008 02:23 AM

Amazing! I never knew it was this easy to find future/previous dates and times!

Salathe 09-15-2008 04:20 PM

Looking forwards, with more recent versions of PHP (5.3 I think) we can make use of the DateTime and DateInterval objects. For example, to add three weeks we could do the following:

PHP Code:

<?php header('Content-Type: text/plain;charset=utf-8'); error_reporting(E_ALL E_STRICT);

date_default_timezone_set('Europe/London');

$now      = new DateTime();
$future   = clone $now;
$interval = new DateInterval('P3W');
// or, $interval = date_interval_create_from_date_string('+3 weeks');

$future->add($interval);
// or, date_add($future, $interval);

echo 'Current time: ',
     
$now->format('jS M Y H:i:s'),
     
PHP_EOL,
     
'Future time: ',
     
$future->format('jS M Y H:i:s');



All times are GMT. The time now is 11:06 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0