Adding a day to a date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psmshankar
Forum Commoner
Posts: 96
Joined: Tue Aug 06, 2002 4:25 am
Location: India

Adding a day to a date

Post by psmshankar »

Hi..
how to add a given number of say to a date value??
i have to discard the data in my table which are 3/4 or
whatever days(specified in table) older that posted date...
lets say posted date is 2002-11-05 and another column contains the max days is 5
so 2002-11-05 + 5 days = 2002-11-10
this is what i need to get??? how 2 do it in PHP?
is there any function??
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if you store that data in a database let the db perform the the calculations.
e.g. http://www.mysql.com/doc/en/Date_and_time_functions.html
You can use those functions in SELECT/DELETE/UPDATE WHERE-clauses

(although php is capable of handling it http://www.php.net/manual/en/ref.datetime.php)
mindmeddler2002
Forum Newbie
Posts: 21
Joined: Mon Nov 04, 2002 3:09 pm
Location: US, PA, Harrisuburg

Post by mindmeddler2002 »

on a win computer, i dont think this function works with unix...

anyways...

$thedate = date(" ");

so u could so

2 digits shows 0 i think in them all
the date function is case sensitive

m = month //01 or 11
d = day //31 or 02
y = year /87 ot 02

anyways u could put these all into seperate vars

$day = date("m");
$month = date("d");
$year = date("y");

then u could maniplulate them any way u want. No Guilty Pleasure....

If u needed to save it to a file, u could record it like this
$thedate = date("m:d:y:");

then u could string tolken to break it back apart
$day = strtok($thedate, ":");
$month = strtok($thedate, ":");
$year = strtok($thedate, ":");
$n_field=strtok(":");

check the manual for proper syntax, this is off my head
but it will work

i use this, i date and timestamp posts
then i can automaticly remove them if there so many days old

here is the catch though
first the page needs loaded for it to run
if it was posted on the 7, and its to be removed after the 8th.
and the page was not ran for almost a month
it would not remove it if its less than 7...

so count in months, and also count in years...
i like to account for anything
makes the code longer
and makes me look like i know a little :oops:
Post Reply