Dynamic Copyright Dates - Now it's easy in 2022

Every new year, there are messages about “Remember to update your Copyright dates”. There are several JS and PHP snippets flying around that can help you do this. I had an idea today to make this as simple as possible for you. I shipped two updates today to make your lives easier.

  • Foundation v6.10.6 adds new date helper utility classes
  • Tardis v1.6.0 has a new Tardis Helper stack. This will be good for non-F6 users/themes.

With these new versions, you can simply place this wherever your copyright goes…

Copyright <span class="current-year">2021</span> My Company

Wherever you place the current-year class, the contents of that will be replaced with the current year on page load. In the example above, I supplied a default of 2021. That will get replaced with the current year (now 2022) on page load.

But wait, there is more…

I figured while I was doing this, why stop at just the year. You have access to the following utility classes. Just like the example above, the current time data will populate where you place the class.

current-year
current-month
current-day
current-hour
current-minute
current-second
current-weekday
current-timeZoneName
current-dayPeriod

current-date
current-time
current-dateTime

The last 3 classes will actually output an actual full date time string. What is even better is that all output is 100% localized for the website’s language.

You have some flexibility with the formatting. The Tardis stack has options in the stack. With the Foundation 6 utility classes, there is a small JS snippet that is documented in the Utilities class section on the F6 Demo site.

If you don’t have Foundation 6 or Tardis, check them out…

https://www.foundationstacks.com/demo/

11 Likes

OK. While I would appreciate it if you were to purchase one of the stacks above, here is a free snippet that will give you the same functionality as above from the Copyright example.

Place this in the JavaScript tab in the site wide code in your project.

document.addEventListener("DOMContentLoaded", () => {
    Array.from(document.getElementsByClassName("current-year")).forEach(e => e.innerHTML = new Date().getFullYear());
});
10 Likes

Damn.

1 Like

Hey, Joe, @joeworkman

Maybe you can help me with a different but related issue. Let me explain.

Every time I make an update to a specific page, I time-stamp that update manually. This is not the same as copyright – just the last update to the page. Is there a way to automate that process? It would have to change the time-stamp only when there is an actual change on the page, not every time the page is published. Doable?

Try this

My Tardis stack can do this for you as well. It can display the exact date and time that the webpage was published. You have full control over the format as well.

@joeworkman The question was imho:

It would have to change the time-stamp only when there is an actual change on the page, not every time the page is published. Doable?

You could only publish the pages that you change, then that would be true.

How else would the page change without publishing it? I guess something like Total CMS. to update the content. You could then use the same CMS to update the date.

@pmjd Regretfully Realmac hasn’t published any changes for RapidWeaver that fixes the inability to change the format of the %last_published% date stamp, since I shared that information back in 2017.

@Rovertek It sounds like you need to buy a copy of my LastPublished stack. It reads the date / time the webpage was last updated and outputs it in any format you want. It will work if you edit the page outside of RapidWeaver (via FTP / text editor) too. But obviously it will not work for dynamic content coming into the page from somewhere else, like AJAX, iFrames, PDF embeds etc.

2 Likes

Hey, Will, @willwood,

You mean your LastUpdated stack? Thanks for heads-up. I didn’t know that stack existed. And free, no less… Donation is on its way.

I’ll give it a try later today.

And Joe, sorry for hijacking your thread.

3 Likes

@Rovertek I’m on my phone currently. I can’t tell if this forum thread is public or not. But it was one of many new and updated addons released last year:

3 Likes

On my sites I just use some simple php code to update my copyright. In my RW project file I go to the General page in Settings. In the Footer field I enter the following:

<?php echo date("Y"); ?>
2 Likes

@forteweb

Is there such a similar PHP code also for always outputting the date of the next Saturday or Sunday?

Sure. Here is some code from w3schools.com showing the next 6 Saturdays.

The example below outputs the dates for the next six Saturdays:

Example
<?php
$startdate = strtotime("Saturday");
$enddate = strtotime("+6 weeks", $startdate);

while ($startdate < $enddate) {
  echo date("M d", $startdate) . "<br>";
  $startdate = strtotime("+1 week", $startdate);
}
?>

Just modify this code to get what you need.

There is support for smart dates like this in my Tardis Time stack.

@joeworkman

Really? I bought the stack a few days ago but didn’t find that exact feature.

Where can I find the feature and are there any instructions?

Its in Tardis Time.

CleanShot 2022-01-12 at 17.35.13

ok. i found that section.

but, how do i create my own time-string placeholder with this Tardis-Stack similar to current-date, current-year or the %last_published% date stamp?

If you change that Display setting, you will see other options like Publish Date.

As for the various classes, have a look at my live stream that I did yesterday.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.