Thanks once again djr33! I seem to be getting somewhere now!!!
Code:
<?php
$startprice=7500;
$dailychange=25;
$first_date=mktime(12,0,0,1,16,2010);
$second_date=mktime(12,0,0,4,4,2010);
$days=$second_date-$first_date;
echo "This sale started on " . $first_date . "<br />";
echo "Today's date is " . $second_date . "<br />";
echo "Sale start price was $" . $startprice . "<br />";
echo "Daily reduction amount is $" . $dailychange . "<br />";
echo "Number of days since sale started is " . $days/(60*60*24) . "<br />";
echo "The price today is $" . ($startprice-(($days*$dailychange)/(60*60*24)));
?>
The above produces the desired result, but not every time! For instance, using Jan 16, 2010 as the First Date and Mar 4, 2010 as Second Date, I get this result:
This sale started on 1263643200
Today's date is 1267704000
Sale start price was $7500
Daily reduction amount is $25
Number of days since sale started is 47
The price today is $6325
However, if I use same First Date and Apr 4, 2010 as Second Date, I get this result:
This sale started on 1263643200
Today's date is 1270378800
Sale start price was $7500
Daily reduction amount is $25
Number of days since sale started is 77.958333333333
The price today is $5551.0416666667
My ‘days’ figure is out by 0.0416666667, or 1/24th. How can I ensure the ‘number of days’ figure is a full integer. I have tried ‘ceil’ and ‘round’, without luck?
My ultimate goal is for the ‘second_date’ variable to be automatic, ie the actual date at the time that the page is served.
Of course, the last line is the one that will be displayed on the website, but I have shown them here just to help with producing the script.
Bookmarks