One of my client’s websites requires regular updates where a “Sale” graphic is shown to visitors between certain dates. Rather than manually updating the site at those specific dates (and having to be in front of the computer on those dates) I wrote a little script so the graphic just pops up if the current date falls between the range I specify.

<pre class="lang:php decode:true " title="If Within Date Range"><?php
	$start_date = "2016-02-19"; // Change this
	$end_date = "2016-02-24"; // Change this

	/* Don't change below here */

	$start_ts = strtotime($start_date);
	$end_ts = strtotime($end_date);
	$cur_ts = strtotime(date('Y-m-d'));
	if (($cur_ts >= $start_ts) && ($cur_ts <= $end_ts)) {
		?> <img src="path/your-image.jpg" /> <?

To use the script just copy and paste it in your html. Change the start and end dates in the first two lines. Change the img source to your path and image. Done!

To see other php snippets by me click here.