Jump to content

Hanna Code Current date


OllieMackJames
 Share

Recommended Posts

In the procache forum I posted about my hanna code solution to show the current date on a page.

Posting here so others can use it if needed.

Before I used a document.write solution, but google pagespeed gave warnings with that.

I use this on salespages where I want the visitor to see the current date.

Works great, I use the html below as [[date]] hanna code

<p id="date"></p>
<script>
days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
months = ["Januari","Februari","March","April","May","June","Juli","August","September","October","November","December"];
d = new Date();
datum = '' + days[d.getDay()] +', '+ months[d.getMonth()] + d.getDate() + ', '+ d.getFullYear() + '';
document.getElementById("date").innerHTML = datum;
</script>

 

  • Like 1
Link to comment
Share on other sites

Note that when using id="date" you may only use one date on one page. I'm not using HannaCode at all, maybe you can use PHP to generate an unique id?

<?php $id = "date_".uniqid(); ?>
<p id="<?= $id ?>"></p>
...
document.getElementById("<?= $id ?>").innerHTML = datum;

 

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...