Hello again Code Experts. What is the .html code to include for current year in the footer, that update it automatic every new year? Probably a messy java script that has to be inserted in the <head> + in the <body> + a separate file.js, or is there an easier solution, like the sister to: <?php echo date('Y'); ?> The long version will do good if nothing easier is available The .PHP version that I asked for recently is here: http://forums.digitalpoint.com/showthread.php?t=1077580 Thanks in advance programmers, Justin
Uhh that PHP code will automatically update with the current year. So if its 2008 it will display 2008, if its 2025 it will display 2025. What exactly are you trying to do?
<? echo date("Y"); ?> is the easiest way. It can also be done in javascript with: [core] <script type="text/javascript">today=new Date();year=today.getYear();document.write (year);</script> [/core] However, I do not see why you wont use php if your server supports that, as it will be the most crossbrowser script.
<script type="text/javascript"> <!-- var today = new Date(); function takeYear(theDate) { x = theDate.getYear(); var y = x % 100; y += (y < 38) ? 2000 : 1900; return y; } document.write(takeYear(today)); </script> Code (markup):
Thanks for your input. I'm trying this now and I suppose that I paste the code in the <head>code</head> but what is the full code to use where it should be printed out in the footer? Copyright (year) Justin Thanks again
Update: The only one that works in Internet Explorer is the one below. (Other gets the error message: Copyright Code corrupted. Insert fresh copy. ) All 3 above codes works in Firefox. [core] <script type="text/javascript">today=new Date();year=today.getYear();document.write (year);</script> [/core] Code (markup):
This one works in IE, the result is "2008" right now, but in Firefox it is "108". This page <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>GetYear</title> </head> <body> <script type="text/javascript"> var today = new Date(); function takeYear(theDate) { x = theDate.getYear(); var y = x % 100; y += (y < 38) ? 2000 : 1900; return y; } document.write(takeYear(today)); </script> </body> </html> Code (markup): got "2008" in both of them. Btw, I tested in IE7 and Firefox3. Check out the tutorial in my last post, I'm sure that'll be helpful.
This is a severe nube question but javascript is greek to me. How do you change the color of the year? Wrapping it in html works in ie but not in ff.
add <style type="text/css"> <!-- .color {color: #******} --> </style> Code (markup): and <span class="color"> <script type="text/javascript"> .......................................... </script> </span> Code (markup):