Self-deleting PHP script triggered by date

Written by Peter Davies on .

We needed a script to run multiple times via CRON up until a specified date, so in one line we created the following snippet:

<?php if (date('Ynj') == "2013129") unlink(__FILE__); ?>

The "Y" is the year (2013), the "n" is a digit value for the month, so 1 in this case, and "j" is the day 29th. When this day is reached the script will execute and remove itself.