How can we help you today?

How to Hide Time When Displaying Contents of a Date Column from a SharePoint Calendar List

By default, when you connect a SharePoint Calendar List to a Design Element, the time is automatically shown with the date:


sample connected Design Element


This article will demonstrate how to hide the time using JavaScript code:


time hidden


TABLE OF CONTENTS


Prerequisites

  • You must have the latest version of ShortPoint SPFx installed on your SharePoint environment.
  • You must be a ShortPoint Designer with an active license.
  • You must have a Design Element connected to a SharePoint Calendar List.
  • Your date property must be in the Subtitle field:


date property


Interactive Tutorial

Before starting the interactive tutorial, copy the JavaScript code below:

const removeTimeFromElements = () => {
  const elements = document.querySelectorAll('#events-image-list .shortpoint-listitem-subtitle');
  
  if (elements.length > 0) {
    elements.forEach(element => {
      const dateTimeText = element.textContent.trim();      
      const dateOnly = dateTimeText.split(' ')[0];
      element.textContent = dateOnly;
    });
    
    console.log(`Updated ${elements.length} date elements`);
    return true;
  }
  
  return false;
};

const checkInterval = setInterval(() => {
  removeTimeFromElements();  
}, 1000);

setTimeout(() => {
  clearInterval(checkInterval);
}, 10000);
NOTEYou can use any ID name you want. Just don’t forget to replace #events-image-list in the JavaScript code above.

Step-by-step Tutorial

Follow the detailed guide below to learn how to hide time in a connected SharePoint Calendar list:


Step 1: Edit the ShortPoint Web Part

  • Go to the SharePoint page you want to use and click Edit:


Edit


  • Close the Toolbox:


close icon


  • Click the ShortPoint tag.
  • Select the Edit Properties icon:


Edit properties icon


Step 2: Edit the Connected Design Element


NOTEBefore proceeding, you must have a Design Element connected to a SharePoint Calendar List. In our case, we will use a connected Image List. In addition, the date property must be in the Subtitle field. For example, our date property is #Start:

date property


  • Click the EasyPass tag of the connected Design Element:


EasyPass tag


  • Select the cogwheel icon:


Cogwheel icon


Step 3: Add an ID Name

  • Click the next icon:


next icon


  • Go to the Custom CSS tab.
  • Write “events-image-list” as the ID name:


ID


NOTEYou can use any ID name you want. Just make sure to take note of it as you will need to replace #events-image-list in the JavaScript code.


  • Click the green check mark.

Step 4: Copy the JavaScript Code

  • Copy the JavaScript Code below:
const removeTimeFromElements = () => {
  const elements = document.querySelectorAll('#events-image-list .shortpoint-listitem-subtitle');
  
  if (elements.length > 0) {
    elements.forEach(element => {
      const dateTimeText = element.textContent.trim();      
      const dateOnly = dateTimeText.split(' ')[0];
      element.textContent = dateOnly;
    });
    
    console.log(`Updated ${elements.length} date elements`);
    return true;
  }
  
  return false;
};

const checkInterval = setInterval(() => {
  removeTimeFromElements();  
}, 1000);

setTimeout(() => {
  clearInterval(checkInterval);
}, 10000);
NOTEIf you used a different ID name, make sure to replace #events-image-list in the JavaScript code.

Step 5: Add the Code Design Element

  • Click the pink plus icon below your connected Design Element:


plus icon


  • Look for Code and select it.

Step 6: Paste the Code

  • Paste the code in the JavaScript field:


paste code


Step 7: Disable Sandbox Mode

  • Go to the Design tab.
  • Disable Sandbox Mode:


disable sandbox mode

  • Click the green check mark.

Step 8: Save

  • Click the eye icon to see your page in real-time:


eye icon


  • Click Save to apply all your changes:


Save


Related articles:

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.

World's best intranet sites are designed using ShortPoint

Get started today! Learn more
See all 89 topics

Start a trial

Ignite your vision. Install ShortPoint directly on your site, or play in sandbox mode. No credit card required.

Get started today

World’s best intranet sites are designed using ShortPoint

Thousands of companies using ShortPoint everyday to design, brand and build award winning intranet sites.

Get started Learn more