Jump to content

Automatically update todays date on daily menu

Go to solution Solved by DavidCliff,

Recommended Posts

Posted

Hi everyone! On my website we have a daily menu that we make daily changes too and currently we are manually changing the date everyday. I added a text block at the top of the page to manually do this. Does anyone know of a way or code to have this change daily to be today’s date? 
 

I have looked into 3rd party widgets but can’t seem to find anything that isn’t a calendar. 
 

please help! Thank you 

  • Solution
Posted

Try this code in a HTML block

<div id="dateContainer">
    <!-- Date will be displayed here -->
</div>

<script>
    const dateContainer = document.getElementById('dateContainer');
    const currentDate = new Date();
    const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
    const formattedDate = currentDate.toLocaleDateString(undefined, options);
    dateContainer.textContent = formattedDate;
</script>

 

  • 3 weeks later...
Posted
On 7/11/2024 at 4:06 AM, HanasakiSushiBar said:

David, thank you so much! Can you help me learn how to fix the font style and size so that it can match the rest of the website? 

I think you can add this code under to adjust size

<style>
  #dateContainer, #dateContainer * {
  	font-size: 18px !important;
  }
</style>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Create an account or sign in to comment

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

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.