Skip to main content
Is there a way to wright a Validation rule that only allows Date/Time fields to contain certain values?

 

Our company has specific appointment windows of 8am to 12pm, 12pm to 4pm and 4pm to 8pm.  No matter how many times I tell people to only select these options in our Start and End Times for Appointments they still select others.
1 Antwort
  1. 20. Mai 2018, 08:50
    Hi Joshua,

     

    Below is the validation rule for your case

    OR(

    Start_Date_Time__c > End_Date_Time__c ,

    AND(

    VALUE(MID(TEXT(Start_Date_Time__c -TZOffset/24), 12, 2))>=8,

    VALUE(MID(TEXT(Start_Date_Time__c -TZOffset/24), 12, 2))<12,

    NOT(VALUE(MID(TEXT(End_Date_Time__c -TZOffset/24), 12, 2))<12)

    )

    ,

    AND(

    VALUE(MID(TEXT(Start_Date_Time__c -TZOffset/24), 12, 2))>=12,

    VALUE(MID(TEXT(Start_Date_Time__c -TZOffset/24), 12, 2))<16,

    NOT(VALUE(MID(TEXT(End_Date_Time__c -TZOffset/24), 12, 2))<16)

    ),

    AND(

    VALUE(MID(TEXT(Start_Date_Time__c -TZOffset/24), 12, 2))>=16,

    VALUE(MID(TEXT(Start_Date_Time__c -TZOffset/24), 12, 2))<20,

    NOT(VALUE(MID(TEXT(End_Date_Time__c -TZOffset/24), 12, 2))<20)

    )

    )

     

    Replace TZOffset value according to your time zone. e.g For Easter Daylight Time(America/New_York), it should be "-4". 
0/9000