Forum Moderators: phranque
I wish to sell items on my website, but reducing the price each day.
For example, I want to start with a fixed amount (say $1000), then automatically reduce this by say $5 per day. I would need to be able to adjust the 'starting amount' and 'reduction amount' for each product or website, but ultimately, the date each day would determine the amount displayed for that day. The result - Day 1 would be $1000; Day 2 would be $995; Day 3 would be $990 etc.
Is it possible to do this and if so, could somebody please provide me with some code? I so hope someone can help me.
Kind regards
what language are you programming in?
I'll lend you an untested PHP solution...
<?php
$originalprice=1000;
$todaydate=getDaysSince1970(Date());
$startdate=getDaysSince1970("2005-12-25");
$dailyreductionamount=5;
$todayprice = $originalprice - ($todaydate-$startdate)*$dailyreductionamount;
echo $todayprice
?>
you'll need that function getDaysSince1970... hmm... where did I put that... maybe it's in my other pants
I'm not quite sure what your last sentence means? Perhaps I'm just webmasterly-challenged!
It looks like the perfect solution to my problem, but how do I get the function to work please?
this solution leans heavily on getting an integer count of the number of days since some arbitrary other date.
Say you choose Feb 3
Date1 is Feb 24, which is 21 days after the origin date.
Date2 is Feb 21, which is 18 days after the origin date.
So 21-18=3; thus 3 days have passed between Date1 and Date2.
That math works whether your point of reference is 21 days ago or 432,336 days ago.
You need a function that will tell you how many days have elapsed since some other fixed point in time. UNIX timestamps use the arbitrarily-chosen date of January 1, 1970.
I don't have my PHP brain on today, so I can't think of the way to get that number... I am pretty sure it's a built-in function, like GetDate() or DateDiff() or ... something
Um, Did you mention what programming language you'll be using?