Page 1 of 1

Adding a day to a date

Posted: Wed Nov 06, 2002 10:40 am
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??

Posted: Wed Nov 06, 2002 12:01 pm
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)

Posted: Wed Nov 06, 2002 1:20 pm
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: