snipt

Ctrl+h for KB shortcuts

JavaScript

show content based on date

1
2
3
4
5
6
<script type="text/javascript">
	var myDate=new Date();
	myDate.setFullYear(2009,5,7);
	var today = new Date();
	if (today>myDate){document.getElementById('hidden').style.display = 'none';}
</script>
https://snipt.net/embed/782b5aa9783653194215d470f5078eee/
/raw/782b5aa9783653194215d470f5078eee/
782b5aa9783653194215d470f5078eee
js
JavaScript
6
2019-07-19T03:48:58
True
False
False
/api/public/snipt/6296/
show-content-based-on-date
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="o">&lt;</span><span class="nx">script</span> <span class="nx">type</span><span class="o">=</span><span class="s2">&quot;text/javascript&quot;</span><span class="o">&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">var</span> <span class="nx">myDate</span><span class="o">=</span><span class="k">new</span> <span class="nb">Date</span><span class="p">();</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">myDate</span><span class="p">.</span><span class="nx">setFullYear</span><span class="p">(</span><span class="mi">2009</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">7</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="kd">var</span> <span class="nx">today</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">();</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">if</span> <span class="p">(</span><span class="nx">today</span><span class="o">&gt;</span><span class="nx">myDate</span><span class="p">){</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s1">&#39;hidden&#39;</span><span class="p">).</span><span class="nx">style</span><span class="p">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s1">&#39;none&#39;</span><span class="p">;}</span> </span><span id="L-6"><a name="L-6"></a><span class="o">&lt;</span><span class="err">/script&gt;</span> </span></pre></div> </td></tr></table>
date, display, javascript