After spending and hour updating my client’s copyright information I thought to myself, “There has to be a better way”. So I made a script that will determine the start date and automatically shows the current year.

This is just a little script that I use in the bottom of all the sites my company creates so we don’t spend so much time changing the date at the bottom of the page when we enter a new year.

First we have to establish the date the site was created. We need a full string to compare so the month and date don’t really matter. We just need a full date or the DateFormat function will not understand what is it we are trying to tell it.

<!--- the year the site was created --->
<CFSET startYear = DateFormat('1/1/2001', 'yyyy')>

Now we have to determine what year we are currently in. This is easy we just use the ColdFusion function now() in place of the actual date.

<!--- the current year --->
<CFSET nowYear = DateFormat(now(), 'yyyy')>

The next and final step is to output the dates and use an IF statement to determine if the startYear and nowYear date are different.

<!--- output the date --->
<CFOUTPUT>
   &copy; #startYear#
   <!--- if the startYear and nowYear are different then show the beginning and ending years --->
   <CFIF startYear neq nowYear>
      - #nowYear#
   </CFIF>
</CFOUTPUT>

THE SITE NAME HERE

That’s it. Now you’ll never have to change the copyright year again. Now just use this as an include on the page you would like to display the copyright info on.

About This Tutorial
Author: Jeff Sanders
Skill Level: Beginner 
 
 
 
Platforms Tested: CFMX
Total Views: 34,724
Submission Date: January 06, 2005
Last Update Date: June 05, 2009
All Tutorials By This Autor: 1
Discuss This Tutorial
Advertisement

Sponsored By...
Powered By...