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
Rohit PaulRohit Paul 

Date Validation for 2 Months window

Hi,

I need to place a validation on one of my date fields in a Customs Object.
The following validation is required:

Lets say, the date today is 4-June-2012.
I need to place a validation where if the user selects any date lesser than 1-May-2012 the system should prompt a message on the field stating that the "Update can be done for current and previous month only".

Which means that to create a record the date selection has to be within the current month and the previous month.

Kindly suggest.
Thanks

Navatar_DbSupNavatar_DbSup

Hi ,

 

Try the below Validation rule for reference(CustomDate is date type field):

 

if( DATE(year( CustomDate__c ),month(CustomDate__c )-2,day(CustomDate__c )) >  PRIORVALUE(CustomDate__c ),true,false )

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Rohit PaulRohit Paul

Hi,

 

This validation is okay if the transaction is withing the year.

There is an issue when the Month entry is in January.

 

Eg.

Lets say the current date is 12-Jan-2012.

A new record needs to be updated.

 

In this case, the validation should allow the user to select any date starting from 1-Dec-2011 till 12-Jan-2012. (2 months window)

Any day before 1st Dec 2011, the system should not allow.

 

Can you suggest a validation for such case?

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below Validation rule:

 

IF( OR(MONTH( newpakge__SLAExpirationDate__c )  =  MONTH(TODAY() ), AND(MONTH( newpakge__SLAExpirationDate__c ) <= MONTH(TODAY() ),MONTH( newpakge__SLAExpirationDate__c )  >=  MONTH(TODAY() )-1) )  , false, true)

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

kcplusplus90kcplusplus90


IF(
OR(
NOT(MONTH(SLA_ExpirationDate__c) = MONTH(PRIORVALUE(SLA_ExpirationDate__c))),
NOT(MONTH(SLA_ExpirationDate__c) = MONTH(PRIORVALUE(SLA_ExpirationDate__c)) - 1)
), true
IF(
AND(
MONTH(PRIORVALUE(SLA_ExpirationDate__c)) = 1,
OR(
AND(
NOT(MONTH(SLA_ExpirationDate__c) = 1)
NOT(YEAR(SLA_ExpirationDate__c)) YEAR(PRIORVALUE(SLA_ExpirationDate__c))
),
AND(
NOT(MONTH(SLA_ExpirationDate__c) = 12)
NOT(YEAR(SLA_ExpirationDate__c)) = YEAR(PRIORVALUE(SLA_ExpirationDate__c)),
)
)),
true,
false
))

Rohit PaulRohit Paul

Hi,

 

I tried to prepare the validation and the following code worked:

 

IF
(MONTH(Date_of_Expenditure__c) = 1,Date_of_Expenditure__c < DATE((YEAR(TODAY())-1),12,1),Date_of_Expenditure__c < DATE(YEAR(TODAY()), (MONTH(TODAY())-1), 1))

 

Please check if this is okay.

Thanks