Simple tricks to change the YEAR? -...

User 3004957 Photo


Registered User
866 posts

Hi, I supposed that all our websites will have the 'year' shown at the bottom of each and every page. I always use the Ctrl+H replace command to change the year when a new year arrives, it's easy, but after that I will have to upload to update all my pages on the server just because of that little changes. Imagine I got 5000 pages on a site, the uploading can take some time.

I ever created an image having the year '2007' on it and then place the image on every page. When 2008 arrived, I only changed and upload the image file and every page gets changed. But I think there's a better way without using image file. Anyone got any smart tactic or script that can share with me? I would appreciate that very much. Thanks. :)

Laura

P.S. In case you don't know what 'year' I'm referring to - it's the year date with the copyright symbol at the bottom of a standard web page.
User 122279 Photo


Senior Advisor
14,649 posts
Online Now

Put this bit of code in the body of your document where you want it to appear:

Copyright &copy; <?php
$date = getdate();
echo $date['year'];
?>

To make it work you need to name your files with the extension .php instead of .html

If you want to keep the file extension .html, you can use this script from JavaScript Kit:

<script language="JavaScript" type=
"text/javascript">
<!--

//Script created by Ronny Drappier, http://sipreal.com
//Visit http://javascriptkit.com for this script

today=new Date();
y0=today.getFullYear();

// end hiding --->
</script> &copy; 2004-<script language="JavaScript" type=
"text/javascript">
<!--- Hide from old browsers
document.write(y0);
// end hiding --->
</script> <a href="http://javascriptkit.com">JavaScript
Kit</a>
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com


User 2161343 Photo


Registered User
76 posts

If your site is hosted on a Unix or Linux, you can use this snippet:

<!--#config timefmt="%Y"--> Copyright <!--#echo var="DATE_LOCAL" -->

(Think that's right; it's been a while.)
User 193638 Photo


Registered User
557 posts

That gets me to wondering. For those of us that use SCCP, will the copyright date at the bottom of each page automatically change to the new year? I don't remember doing anything on my part to put it there in the first place. Could be wrong. It's hard to remember, there so much work to making a website.
User 2733 Photo


Ambassador
426 posts

Inger Eik wrote:

Copyright &copy; <?php
$date = getdate();
echo $date['year'];
?>


The function getdate() returns an associative array. There's no need to grab data that won't be used. On the other hand, the date() function returns a date string based on the params you pass in quotes. In this case, I'm asking for the full, four digit year be returned. So, this is much shorter under the circumstances. http://us3.php.net/manual/en/function.date.php

&copy; <?php echo date('Y'); ?>
Let's not get all hurt.
User 122279 Photo


Senior Advisor
14,649 posts
Online Now

Thanks, David. My PHP knowledge has not excelled yet, due to health and other commitments... ;)
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com


User 2733 Photo


Ambassador
426 posts

Inger, you're welcome. Be well and happy new year!
Let's not get all hurt.
User 3004957 Photo


Registered User
866 posts

Hi Paul, I tried your code... it didn't work (my site is hosted on Linux). Then I tried the javascript from Inger, it worked!

Whether it worked or didn't, I'm happy that all of you have spent the effort to help me with this. Paul, Inger, David and Steven... thank you very much. Really appreciate your help. Have a fruitful 2011! :D

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.