Timberline Ridge (timberlineridge) wrote in php,
Timberline Ridge

Generating fortnights using time()

OK, I'm trying to write a script that tells you when your next recycling collection is (don't laugh). In my city, your recycling is collected on a certain day (the actual day depends where exactly you live) every two weeks.

What I'd like to do is have a web page with a list of street names and the date of your next collection, which is generated based on the current date (using time() ). I'm running into a bit of trouble generating the next collection day because it's once a fortnight and I can't just (for example) increment the current time() until I get to the right day because it could be more than a week away.

At the moment I've got all the street names in a database with a timestamp of a known collection. Then I just increment the "known collection" timestamp by two weeks until the value exceeds time().

What I'd like to know is - is there an easier way to do this? I figure once the script has been up and running for a while it's a bit silly to start at a date that was years ago and increment it until it passes the current date.

UPDATE: Sorted it (maybe). I don't have server access to set up a cron job, but I can kind of achieve the same effect by querying and updating the database in the script before outputting the values. Cheers! :) You can see the script in action here (woooo).
  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.