I was recently asked to change the copyright date on a handful of websites. The websites all were using a CMS system, but when the person who built them set them up, they inserted a static year. So, every year someone has to go in and change them. Thankfully, there are only about 10 or so page templates that are used so it is a pretty quick change. However, it would have been much easier if — the person who built the site… added a line or two of code 😉 to pull the year off the server time. This way, every year the date will automatically change… making life easier for someone!
Here are a couple methods that will produce the result we are looking for:
Technically JS is client side, so this option doesn't really pull the date off the server... It pulls it from the clients computer. So, if their date isn't correct this wont be either. But it should work most of the time.
var d = new Date();
Matt is a Systems Development Director for a multinational franchise. Matt has lived and worked in Hawaii, Chicago, South Florida and currently resides outside of Atlanta. He enjoys his hobbies including Technology, Gadgets/EDC, Fountain Pens, Wetshaving, Clocks, Antiques & Coffee. He even roasts his own coffee weekly.