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 09-14-2008, 10:03 PM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default 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
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 09-14-2008, 10:18 PM   #2 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

php Code:
$iToday = time();
$iNext = strtotime('+3 weeks', $iToday);
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote
The Following User Says Thank You to Karl For This Useful Post:
ETbyrne (09-15-2008)
Old 09-14-2008, 10:22 PM   #3 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

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

thanks, but how do i show that as ##/##/## format?
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 09-14-2008, 10:31 PM   #4 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

PHP Code:
echo date('m/d/Y'$iNext); 
Check out the date function on php.net.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
The Following User Says Thank You to xenon For This Useful Post:
ETbyrne (09-15-2008)
Old 09-15-2008, 02:23 AM   #5 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Amazing! I never knew it was this easy to find future/previous dates and times!
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 09-15-2008, 04:20 PM   #6 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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');
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
sarmenhb (10-03-2008)
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 03:31 AM.

 
     

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