Forum Discussion

Dips1997's avatar
Dips1997
Copper Contributor
Feb 07, 2021

How to set time limit for a SharePoint Calendar?

Hi, I have created an event calendar and I want if a user creates a event he/she have option to choose event start and end date with time. This feature is already OOTT but I want to set that end time won't exceed 4 hours from start time.

 

For eg. If start time is 7th feb 2021 10:00AM selected and the end time is 7th feb 2021 03:00 PM selected then it will show that user an error "End time shouldn't exceed 4 hours from Start Time."

Is there any JavaScript code available to help solving this issue or any List Validation formula?? Please help.

1 Reply

  • billthebrewer's avatar
    billthebrewer
    Copper Contributor

    Just found this thread. I was looking for the same thing and I came up with a solution. Go to the calendar you want to set up the time limit for, click on Calendar in the ribbon at the top, then click on List Settings.  In the General Settings, there is an option called Validation settings. Click on that. You'll need to put in a formula to check to make sure that the time doesn't exceed four hours. Here is what I put in: 

    =AND((([End Time]-[Start Time])*24)<=4)

    Then, in the User Message, you'll need to put in a message alerting that the time is longer than allowed. This formula works great for me. Hope you can get it to work.

    EDIT: It's not perfect because for some reason, trying to schedule from 10:00 am until 2 pm returns an error message but if I switch the time from 10:00 am until 1:55 pm, that works. This error also happens from 1 pm until 5 pm and a few other times. I haven't figured out why, yet.

Resources