[PHP] Adding X days to a time string...

2003-11-21 Thread Jeff Lewis
Storing a date in seconds (Unix timestamp) in a database and want to add
X number of days to this. So I want to extend a time by say 5 days, what
is the best method to handle this?
 
It's always stored as a timestamp for a day not an exact time. So dates
are stored as day (March 5th, 2003).
 
Jeff


RE: [PHP] Adding X days to a time string...

2003-11-21 Thread Jay Blanchard
[snip]
Storing a date in seconds (Unix timestamp) in a database and want to add
X number of days to this. So I want to extend a time by say 5 days, what
is the best method to handle this?
 
It's always stored as a timestamp for a day not an exact time. So dates
are stored as day (March 5th, 2003).
[/snip]

http://www.php.net/strtotime

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Adding X days to a time string...

2003-11-21 Thread Jeff Lewis
Sorry, I may have muddled that...the issue isn't converting a string to
a time, it's taking a time (102636 for example) and adding 30 days
to that.

Jeff

-Original Message-
From: Jay Blanchard [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 21, 2003 11:13 AM
To: [EMAIL PROTECTED]; php-gen
Subject: RE: [PHP] Adding X days to a time string...


[snip]
Storing a date in seconds (Unix timestamp) in a database and want to add
X number of days to this. So I want to extend a time by say 5 days, what
is the best method to handle this?
 
It's always stored as a timestamp for a day not an exact time. So dates
are stored as day (March 5th, 2003). [/snip]

http://www.php.net/strtotime

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Adding X days to a time string...

2003-11-21 Thread Kelly Hallman
On Fri, 21 Nov 2003, Jeff Lewis wrote:
 Sorry, I may have muddled that...the issue isn't converting a string to
 a time, it's taking a time (102636 for example) and adding 30 days

Having it in seconds since the epoch makes this pretty easy
(60 * 60) * 24 = 86400 // seconds in a day
(86400 * days) + timestamp

-- 
Kelly Hallman
//Ultrafancy/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Adding X days to a time string...

2003-11-21 Thread joel boonstra
On Fri, Nov 21, 2003 at 11:15:20AM -0500, Jeff Lewis wrote:
 Sorry, I may have muddled that...the issue isn't converting a string to
 a time, it's taking a time (102636 for example) and adding 30 days
 to that.

Ah, but it is an issue of converting a string to a time.  strtotime()
can Parse about any English textual datetime description into a UNIX
timestamp.  It also has a handy optional parameter telling you when to
consider now.  So to add thirty days to now (102636 in your
example):

?php
$now = however_you_get_your_timestamp();
$future = strtotime('+30 days', $now);
?

Such a handy function -- no need to worry about leap years, number of
days in a month, etc...

-- 
[ joel boonstra | gospelcom.net ]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php