<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">

<channel>

 <title>Professors Coding Corner</title>
 <link>http://www.professorscodingcorner.com/</link>
 <description>The coding corner has tutorials and code snippets in both Javascript and Perl.</description>
 <lastBuildDate>Fri, 09 Dec 2011 06:00:00 GMT</lastBuildDate>
 <language>en-us</language>
 
 <image>
  <title>Professors Coding Corner</title>
  <url>http://www.professorscodingcorner.com/gifs/logo.gif</url>
  <link>http://www.professorscodingcorner.com/</link>
  <width>106</width>
  <height>130</height>
 </image>
 
 <item>
  <title>Update Dates Automatically | Professor's Coding Corner</title>
  <link>http://www.professorscodingcorner.com/snippets/dates.shtml</link>
  <guid>http://www.professorscodingcorner.com/snippets/dates.shtml</guid>
  <category>last updated, copyright date, last modified date, current date, current year, update copyright date automatically</category>
  <pubDate>Fri, 09 Dec 2011 06:00:00 GMT</pubDate>
  <description><![CDATA[<h2>Code Snippet: Change Dates Automatically</h2>
<p>Recently, I was updating some of my small on-page javascripts to make them <span title="Unobtrusive: seperating dynamic behavior (the script) from structure (the HTML)" class="hoverTip"> unobtrusive</span>.&nbsp; The three given here are completely unnecessary, but using them helps take some of the burden off a webmaster, so I decided to put them up for you as code snippets. The task that they perform could easily be done with <acronym title="SSI: Server-Side Include">SSI</acronym>, but then your webpage would need to be capable of using it, and the include code (plus the formatting of the date) would have to be on every page.</p>
<p>If you have a copyright year or a current or last-modified date posted on your web pages, these scripts will automatically update them for you.&nbsp; This means you won't have to remember to change them at year's end, or each time you update a page.&nbsp;</p>
<pre>
 1 function currentYear()
 2 {  
 3   if (!document.getElementById("currentyear")) return false;
 4   var obj = document.getElementById("currentyear");
 5   var today = new Date();
 6   var year = today.getFullYear();
 7   txt = document.createTextNode(year);
 8   obj.appendChild(txt);
 9   return true;
10 }

 1 function currentDate()
 2 {
 3   if (!document.getElementById("currentdate")) return false;
 4   var obj = document.getElementById("currentdate");
 5   var monthtext = new Array("January","February","March","April","May","June",
       "July","August","September","October","November","December");
 6   var today = new Date();
 7   var month = today.getMonth();
 8   var date = today.getDate();
 9   var year = today.getFullYear();
10   var currentdate = monthtext[month] + " " + date + ", " + year;
11   var txt = document.createTextNode(currentdate);
12   obj.appendChild(txt);
13   return true;
14 }

 1 function lastUpdated()
 2 {
 3   if (!document.getElementById("lastupdate")) return false;
 4   var obj = document.getElementById("lastupdate");
 5   var monthtext = new Array("January","February","March","April","May","June",
       "July","August","September","October","November","December");
 6   var modified = new Date(document.lastModified);
 7   var month = modified.getMonth();
 8   var day = modified.getDate();
 9   var year = modified.getFullYear();
10   var lastupdate = "Last update: " + monthtext[month] + " " + day + ", " + year;
11   var txt = document.createTextNode(lastupdate);
12   obj.appendChild(txt);
13   return true;
14 }
</pre>
<p><b>How to use the script:</b></p>
<p>1) You don't need to make any changes to the above functions.&nbsp; They are written as independent scripts, so any or all of them may be used.</p>
<p>2) Follow the instructions on the main Snippets Page for how to install a javascript function that runs at load time.</p>
<p>3) Put the following code on your webpage wherever you want one of the dates to appear.&nbsp; I use a &lt;span&gt; tag, since then the date can be inserted on the same line as other text, but you can use a &lt;p&gt; or a &lt;div&gt; if this doesn't matter.</p>
<pre style="color:red;">
&lt;span id="currentyear"&gt;&lt;/span&gt;
</pre>
]]></description>
 </item>

</channel>
</rss>
