Content Expiration Timer
Manage limited-time offers. This script compares the current date against an expiration date and automatically hides an element when the time is up.
Limited Time Offer!
This box will disappear if the date is past Jan 1, 2025.
Offer Expired! The content has been hidden.
Copy the Script
<div id="myOffer">This offer expires soon!</div>
<script>
// Set expiration date (Year, Month (0-11), Day)
var expireDate = new Date(2025, 0, 1); // Jan 1, 2025
var today = new Date();
if (today > expireDate) {
document.getElementById("myOffer").style.display = "none";
}
</script>
Frequently Asked Questions
No. The content is hidden using CSS (`display: none`), so it is still in the source code. Do not use this for securing files, only for visual UI changes.
Yes. Just reverse the logic: if `currentDate > targetDate`, set `display: block` instead of `none`.
It uses the user's local system time by default. If you need a strict global expiration (e.g., stopping a sale at midnight UTC), you should handle it server-side with PHP.