Php to automatically increase date after date has been reached?

by 8 replies
10
Hi,

I'd like to make an "special offer" on a site that lasts 1 week and after this week is over it gets extended for another week and so on.

How can you do this in PHP?
#programming #automatically #date #increase #php #reached
  • If it is just to display a date that expires in a week then I would put the expiry date in a MySQL database or a text file if you do not have a database. I would then create a script that queries the database to see if the current date matches the date in the database or file.

    If the date matches or is greater then I would update the expiry date in the database or text file to a new 1 week expiry. If it is not then I would display the date that is in the database or file.

    There maybe better ways to do this which someone else will point out I'm sure but it's the first thing that comes to mind.
    • [1] reply
    • To store the start date...

      file_put_contents('filename', time());

      To check 7 days...

      $timeStart = file_get_contents('filename');
      $timeNow = time();
      if($timeNow > $timeStart + (7 * 24 * 60 * 60)) {
      // ... do stuff here now that 7 days have elapsed.
      }


      Should get you started ;-)

      However, as Istvan pointed out, it is best you create a new offer after day 7. Simply resetting the timer isn't righteous, but this is for you to judge.
      • [1] reply
  • There are ways and any php programmer can help you with that... the question is: should you do it?

    What you plan is called "fake scarcity" and if people realize that your offer is still alive after one week - you may lose any credibility you have.
  • Thanks very much for all these replies - have to try it out and hope it won't be too complicated for a php beginner.
    • [1] reply
    • Why not create a script that rotates offers instead? After 7 days a new deal is presented. You can also have upcoming previews. So if a person doesn't like what you have that week, they can come back and see what you have the next week.

      I hope this helps.
  • @ryanstreet

    This sounds very interesting. Is there any ready-to-go script that offers this?
  • If you always want it to STAY at 1 week, you could use date() and strftime() to always show a time 1 week from now. If you want it to appear that the time IS counting down, you could store their visit date in a cookie, and calculate against that on subsequent visits.

Next Topics on Trending Feed