---
title: "Self-deleting PHP script triggered by date"
date: "2013-03-06"
path: "/104-self-deleting-php-script-triggered-by-date.html"
section: "/ramblings"
aliases:
  - "/104"
  - "/104-self-deleting-php-script-triggered-by-date"
  - "/104.html"
  - "/ramblings/104-self-deleting-php-script-triggered-by-date.html"
---

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.
