+ Start a Discussion
Eric PohlabelEric Pohlabel 

Error creating validation rule based on Date - DATEVALUE error

I have a business need to restrict a picklist value if a particular DateTime field is within 180 days.  My rule looks like this:
 
AND(
ISPICKVAL(Recurring_Post__c , "Yes"),
 DATEVALUE( Last_Drafted_Date__c )<NOW()-180)
Last_Drafted_Date__c is of type DateTime which is why I am using the DATEVALUE function to return a Date BUT I keep getting the folowing error:  Incorrect argument type for function 'DATEVALUE()'

I cant seem to figure out what Im doing wrong!
Best Answer chosen by Eric Pohlabel
Charisse de BelenCharisse de Belen
Hi Eric,

Instead of using NOW(), try using TODAY().

You might also want to rethink your date comparison. Right now, your formula is checking if Last_Drafted_Date__c is more than 180 days in the past. If you want to check if Last_Drafted_Date__c is within 180 days, you should try this:
AND(
  ISPICKVAL( Recurring_Post__c , "Yes" ),
  ( DATEVALUE(Last_Drafted_Date__c) - TODAY() ) < 180
)

I hope this helps!

All Answers

Charisse de BelenCharisse de Belen
Hi Eric,

Instead of using NOW(), try using TODAY().

You might also want to rethink your date comparison. Right now, your formula is checking if Last_Drafted_Date__c is more than 180 days in the past. If you want to check if Last_Drafted_Date__c is within 180 days, you should try this:
AND(
  ISPICKVAL( Recurring_Post__c , "Yes" ),
  ( DATEVALUE(Last_Drafted_Date__c) - TODAY() ) < 180
)

I hope this helps!
This was selected as the best answer
Eric PohlabelEric Pohlabel
Thanks for the reply - but this formula also returns the same "Incorrect argument type for function 'DATEVALUE()" error.
Charisse de BelenCharisse de Belen
That's odd. Are you sure Last_Drafted_Date__c is a DateTime field? I tested this validation rule on a custom DateTime field in my org, and it is working fine for me.
Eric PohlabelEric Pohlabel
Its now WORKING!!  Thank you so much!