Forum Moderators: phranque

Message Too Old, No Replies

Automatic price reduction code required

website price reduction code

         

alphachance

3:18 pm on Feb 23, 2006 (gmt 0)



I hope this is the correct forum for my first post. If not, please accept my apologies and be kind enough to point me in the right direction! Thanks.

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

httpwebwitch

9:21 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, alphachance!

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

alphachance

12:08 am on Feb 24, 2006 (gmt 0)



Thanks for your reply httpwebwitch.

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?

httpwebwitch

4:17 pm on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, well you follow the math and the logic in the first part, right?

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?