SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
Thread: Math Equation
-
Dec 19, 2006, 07:27 #1
Math Equation
I am trying to setup a small script to increase the cost of a service up to the date of Feb 28th. At this date the original price will be reached. I would like to start out at around 10.50 and go up to 14.99 (original price) dynamically. I.e the price tomorrow will be higher than the price is today. I am not the greatest at formulating equations, but I have done a little bit to find out how many days until Feb 28th. Could anyone help me with the math?
Thanks!!
PHP Code:<?
$sale_end = mktime(0, 0, 0, 2, 28, 07);
$now = mktime();
$diff = $sale_end - $now;
$num_days = round($diff / 86400);
?>s c r i p t s f o r y o u . n e t
ScriptsForYou
-
Dec 19, 2006, 08:26 #2
- Join Date
- May 2006
- Location
- Austin
- Posts
- 401
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
There is a lot of unnecessary code in here. It would be easier to specify that there are 70 days left, and figure it out from there, but this is using what you started with.
PHP Code:<?PHP
$then = mktime(0, 0, 0, 2, 28, 07); //final day
$start = time(0, 0, 0, 12, 19, 06); //start day
$now = time(); //current day
//find total days
$timeDiff = $then - $start;
//find remaining days
$daysRemaining = $then - $now;
$days = floor($timeDiff/60/60/24);
//70 days today - Might as well make this a pre-defined variable since nothing is going to change
$daysLeft = floor($daysRemaining/60/60/24);
$originalPrice = 10.50;
$finalPrice = 14.99;
//calculate how much the price has to go up
$priceDiff = $finalPrice - $originalPrice;
//calculate the increase per day
$priceInc = $priceDiff/$days;
//find how many days have gone by, multiple by the price increment and add to the original
$finalPrice = round((($days - $daysLeft) * $priceInc) + $originalPrice,2);
echo $finalPrice;
?>Merchant Equipment Store - Merchant Services, POS, Equipment, and supplies.
Merchant Account Blog | Ecommerce Blog
Bookmarks