function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ravi_SFDCRavi_SFDC 

Datetime datatype Validation Rule

I do have Date/Time DataType for Start Date and End Date

Start Date and End Date every time should be EQUAL and both can't be on future dates. But can be on previous dates.

The issue is Start Date is TODAY, but the End Date is taking the value as the Previous Date, which shouldn't happen.

FINAL OUTPUT needed, START DATE and END DATE should be the SAME every time. If we have the record for the same date, we shouldn't allow duplicate data record.

Your help would be really appreciated.

Regards Ravi

 

AND(
    NOT(ISNEW()),
    ISBLANK(Id),
    NOT(ISBLANK(Start_Date_Time__c)),
    NOT(ISBLANK(End_Date_Time__c)),
    Start_Date_Time__c >= DATEVALUE(NOW()),
    End_Date_Time__c >= Start_Date_Time__c,
    NOT(
        AND(
            Start_Date_Time__c >= DATETIMEVALUE(FLOOR(TEXT(Start_Date_Time__c))),
            End_Date_Time__c < DATETIMEVALUE(FLOOR(TEXT(End_Date_Time__c))) + 1
        )
    )
)
Sai PraveenSai Praveen (Salesforce Developers) 
hi,

can you check below formula.
 
OR( Start_Date_Time__c <> End_Date_Time__c , DATEVALUE(Start_Date_Time__c)> TODAY(),DATEVALUE(End_Date_Time__c)>TODAY())

Please note that we cannot check duplicate value using validation rules. You may have to use trigger in this scenerio I guess.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
Ravi_SFDCRavi_SFDC

Hi,

Thank you. I have tried this. This will not work if i select different time for the same date.

Example:

Start Date: Mar 15,2023: 6 AM         End Date: Mar 15,2023: 6 PM

Start Date: Mar 15,2023: 7 AM         End Date: Mar 15,2023: 7 PM

Both records would get saved in the above scenario.

The record shouldn't be saved even i do have different time for the same day.

 

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Ravi,

I guess you dont have 24 hours enabled on time because of which you are facing the issue. Let me check for 12 hours format.

Thanks,
 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Ravi,

I changes my Loccale to 12 hour format and checked and it is working as expected. I gave date as below.

Start Date: Mar 7 11:30 am End Date : Mar 7 11:30PM.

The record did not got saved can you check if validation rule is active

Thanks,