output date from value plus 'x' days

Hi everyone,

I’m trying to output a due date based upon a date plus an amount of days, I’ve tried a few options. At the moment my code is;-

[php]$due_date = $row[‘date’]+$row[‘payment’];
echo “

”.$due_date."";[/php]

so for example the ‘date’ value is 2015-10-01 and the payment value is ‘60’ - this being 60 days. The above code just adds 60 to the value and outputs ‘2075’.

I also tried the below and thought I was onto a winner but no joy…
[php]$date = date_create($row[‘date’]);
date_add($date, date_interval_create_from_date_string("$row[‘payment’] days"));
echo “

”;
echo date_format($date, ‘Y-m-d’);
echo “”;[/php]

thanks

so for example the 'date' value is 2015-10-01 and the payment value is '60' - this being 60 days. The above code just adds 60 to the value and outputs '2075'.

This makes no sense. And you should be doing your date calculations in MySQL. I would show you, but I cant understand what you are doing? What is 2075?

Hi kevin,

2075 is my current output (ie 2015 plus 60), it should be adding 60 days to the date of 2015-10-01 so the actual out should read 2015-11-30

SELECT DATE_ADD(‘2015-10-01’,INTERVAL 60 DAY) AS new_date

Kevin’s may be what you want. But, I feel there is more to this. Is it a onetime fee or recurring? Would you need to select these dates for reminder emails? When they pay, does it remove the date or flag it as now paid off?

Hi Kevin, thanks for your reply… astoneciper is correct in his assumption.

my query lists all of the invoices in the database and echos them within a table. So the ‘date’ value will vary and so will the ‘60’.

so my query is along these lines…
[php]echo ‘

’.$row[‘date’] . ‘’;
echo ‘’.$row[‘payment’] . ‘’;

$due_date = $row[‘date’]+$row[‘payment’];
echo “

”.$due_date."";[/php]

Astonecipher - I’ve not got it that advanced yet in terms of the reminder emails etc, there is also an option on a edit page for the user to click a select box whether the invoice is paid / unpaid.

the due date is more of a prompt for the users as they can see all invoices that are unpaid and when the date for payment is due.

thanks for your input guys

Sponsor our Newsletter | Privacy Policy | Terms of Service