It’s amazing more websites don’t just use: (for example) 1996-<?php echo date("Y"); ?> to always display the correct year and eliminate the need to update every year
I just started a HTML course to add to my Java courses and was going to ask "can't you just add some function to update a variable every time it needs ". So here's my like
My example was assuming the use of php (so file would have to end in .php), if you wanted to do it in javascript and html only, I guess you'd use something like:
<p>1996-<span id="currentYear"></span></p>
<script>
document.getElementById("currentYear").innerHTML = new Date().getFullYear();
</script>
Considering how easy it is to automate this and the wide variety of ways to do it, it's surprising how many big websites don't use this :)
I personally think the server backend would be better for this both as it doesn't rely on the client and also means the client cannot tell it is being updated automatically
Using php and server side updating is the preferred way of doing it and would be what I would use... but if you wanted to do it without learning php then that would be the script you’d use
It’s amazing more websites don’t just use: (for example) 1996-<?php echo date("Y"); ?> to always display the correct year and eliminate the need to update every year
I just started a HTML course to add to my Java courses and was going to ask "can't you just add some function to update a variable every time it needs ". So here's my like
My example was assuming the use of php (so file would have to end in .php), if you wanted to do it in javascript and html only, I guess you'd use something like:
<p>1996-<span id="currentYear"></span></p><script>document.getElementById("currentYear").innerHTML = new Date().getFullYear();</script>Considering how easy it is to automate this and the wide variety of ways to do it, it's surprising how many big websites don't use this :)
Nice , thank you for the example added it to my "cool thing to use.txt" file :D
Happy to help :)
I personally think the server backend would be better for this both as it doesn't rely on the client and also means the client cannot tell it is being updated automatically
Using php and server side updating is the preferred way of doing it and would be what I would use... but if you wanted to do it without learning php then that would be the script you’d use