I maintain several websites that can contain time-sensitive information. Often times I’ll post something that should appear until a certain future date and time. In the past, I’ve set a calendar reminder to prompt me to remove the information from the website. But sometimes I’d get busy and I’d forget!

A simple solution was to write this little snippet of PHP code to automatically ‘hide’ a portion of a web page a the appropriate time.

This PHP function inserts the CSS style attribute of display:none, which hides the respective HTML, plus it doesn’t take up any space on the page.

Here’s how you apply it. Just insert the checkExpiration function on a wrapping tag with the date and time stamp formatted as shown. In this example, the div will appear until 12:00:00 p.m. on April 17, 2015. After that, it will automatically disappear.

 $expiration) {
   		echo "style='display:none;' ";
   }
}

echo date("Y-m-d H:i:s"); 

?>



	
	Check Expiration PHP Snippet



>

Save up to 20% until

Don’t miss this great sale on all styles of men’s and women’s clothing, but only until 00/00/00.