Hello,
I have a field in date-format in my mysql db and I'd like to query the values and add a specific number to the date, so that I would have two results when echoed with php.
This is what I got so far:
I query the date (format: 0000-00-00) from my db and write it into the var $result (date is also the fieldname):
$result = mysql_query("SELECT date,addition FROM testtable");
I do a while loop with the dates showing up and cut the date into stringparts and I want to add the day-part of the result with another field which I call addition here (format: integer), so that I actually make another date using the mkdate-function.
So I do this:
<?php
// mysql query
$result = mysql_query("SELECT date,addition FROM testtable");
while($row = mysql_fetch_object($result)) {
$date = $row->date;
$date = strval($date);
$datepart1 = substr("$date", 8); // this is the day
$datepart2 = substr("$date", 5, 2); // this is the month
$datepart3 = substr("$date", 0, 4); // this is the year
$result_of_addition = intval($datepart1)+intval($row->addition);
$second_date = date ("j.n.Y", mktime(0,0,0,intval($result_of_addition),intval($datepart2),intval($datepart3)));
echo $datepart1.".".$datepart2.".".$datepart3." - ".$second_date;
}
?>
Let's say the results I get from my db are the following:
the first result of field "date" has the value of = 2003-01-21 and
the first result of field "addition" has the value of 8.
The whole thing is that I want the function to recalculate a second date that is still in the future and which depends on the first date whilst adding the field result of "addition" with the first date.
So for example the result of the "echo"-line for above process should look like this:
25.1.2003 - 2.2.2003
So the function should add the "8" to the date I got from the db, however it does not seem to add it right, I get a different result and I do not know what I'm actually doing wrong =(
Does anybody know an answer?