Link to home
Start Free TrialLog in
Avatar of CipherIS
CipherISFlag for United States of America

asked on

HTML Display Current Year

How can I change 2015 below to always display the current year?

<div style="text-align: center; margin-top: -3px">
     Copyright 2015 My Company&#0153.  All Rights Reserved.
</div>
Avatar of Mitchell Milligan
Mitchell Milligan
Flag of United States of America image

If you specifically want an HTML solution there is no way to automate it.  The year can only be hard-coded.

If you are willing to accept a non-HTML solution, almost all hosts now a days have PHP support built in. Simply change the extension of your HTML file to .php and add this one line in the area where you want it to display:

<?php echo date("Y"); ?>
Avatar of CipherIS

ASKER

How about with javascript?  I'm not using PHP so that won't work but thanks for the info.
Javascript could work, though at times can lead to NOSCRIPT errors and not load the year anyways, but you could try:

<p>&copy; Copyright
<script language="JavaScript" type="text/javascript">
    now = new Date
    theYear=now.getYear()
    if (theYear < 1900)
    theYear=theYear+1900
    document.write(theYear)
</script>
ASKER CERTIFIED SOLUTION
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here is another Example using Java Script

<html>
<head>
<script language="JavaScript">
function mdy(todaysdate) {
//calls the function mdy why to get our date
return todaysdate.getMonth()+1+"/"+todaysdate.getDate()+"/"+todaysdate.getYear()
}
</script>
</head>
<body>
<script language="JavaScript">
sampleDate1=new Date()
document.write ("Today's date is "+ mdy(sampleDate1))
</script>
</body>
</html>

Open in new window