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
Arvind VasudevanArvind Vasudevan 

Getting month from DateTime field

I want to create a validation rule on datetime field where datetime should be accepted for the date -30 days from today to today.

Can someone please help me with it?
I tried using Datetimevalue(NOW()) and Datetimevalue(NOW()-30) , which is not working . Also tried with TODAY() instead of NOW().

SandhyaSandhya (Salesforce Developers) 
Hi Arvind Vasudevan,

Use below formula in validation rule

Your datetime feildname  >  (NOW() -30)

and write appropriate error message you want to throw on top of the page or near field.

Please accept my solution as Best Answer if my answer was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, u can give me kudos.


Thanks and Regards


Hey Arvind,

Assume that if you are entering on x_date__c field your validation formalula would be like as below:
OR((TODAY() - x_date__c ) > 29,(TODAY() - x_date__c ) < -30)
if( TODAY() > x_date__c, (TODAY() -  x_date__c ) > 29, (x_date__c - TODAY() > 29 )
Hope this works for you... :) Enjoy coding....

Arvind VasudevanArvind Vasudevan

Hi Jeet / Sandhya,

Thankyou for your suggestions, it was helpful and am able to achieve the task for today and 30 days prior from today. It would be more helpful if you guys let me know how to achieve the same for next 30days from today.

I tried changing the signs and rearranging the datefield and TODAY(), but still its not working.

AND( $User.CMS_Country_Code__c = 'KR',  NOT( OR( Date_vod__c = TODAY(), (TODAY() -  Date_vod__c  ) <= 30 )))
 This works for today and upto 30 days prior from today.I want it to work for next 30days from today too.

My requirement is date has to be accepted for,
1.Upto 30days prior from today
3. Till 30 days from today.

Hope my question is clear.

Thanks in advance. :) 

Deepak RathinaveluDeepak Rathinavelu
Hi Arvind,

try this
AND( $User.CMS_Country_Code__c = 'KR',  NOT( OR( Date_vod__c = TODAY(), IF(TODAY() >= Date_vod__c,(TODAY() -  Date_vod__c  ) <= 30,(Date_vod__c - TODAY()) <= 30))))

Let me know if it worked.

All the best
Deepak Rathinavelu