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
F SmoakF Smoak 

check if datetime field has reached past today's datetime

I have to delete alerts whne expiration datetime has reached today's datetime
My expiration datetime is showing as 2019-10-05T00:00:00.000Z
I want to delete this record on 5th Oct but I am getting unknown error parsing query when I execute in query editor:
Select Id from Alert_vod__c where Expiration_Date_vod__c <= system.now()

Please help.

 
Best Answer chosen by F Smoak
Alain CabonAlain Cabon

Select Id from Alert_vod__c where Expiration_Date_vod__c < 2019-10-06T00:00:00.000Z     ( without quotes, problem of timezone nevertheless)

system.now() doesn't exist but you can use TODAY

Select Id from Alert_vod__c where Expiration_Date_vod__c <= TODAY 

 

All Answers

Alain CabonAlain Cabon

Select Id from Alert_vod__c where Expiration_Date_vod__c < 2019-10-06T00:00:00.000Z     ( without quotes, problem of timezone nevertheless)

system.now() doesn't exist but you can use TODAY

Select Id from Alert_vod__c where Expiration_Date_vod__c <= TODAY 

 
This was selected as the best answer
F SmoakF Smoak
thanks! it worked. 
can u pls check this question posted: https://developer.salesforce.com/forums/ForumsMain?id=9062I000000XkdDQAS
Deepali KulshresthaDeepali Kulshrestha
Hi,

Greetings to you!

Use the below code.
 
DateTime currentTime = System.now();
List <Alert_vod__c> altList = new List <Alert_vod__c>(); 
altList = [Select Id, Expiration_Date_vods__c from Alert_vod__c WHERE Expiration_Date_vods__c <= : currentTime ]; 
System.debug('altList'+altList);

You can use the below link to know more
https://salesforce.stackexchange.com/questions/100187/how-to-compare-datetime-field-with-systemtime-now-in-soql-query

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com