You need to sign in to do that
Don't have an account?
irfan aziz
How to filter a datetime column based on time?
The below select with condition createddate=last_n_days:1 filters last one day data. But I am expecting that we ll need to query multiple times in a day. Is there function that i can use to filter based on hours(like get the date for the last 3 hours or 1 hour).
SELECT AccountId,Amount,CampaignId,CloseDate,CreatedById,CreatedDate,Description,Fiscal,FiscalQuarter,FiscalYear,ForecastCategory,ForecastCategoryName,\
HasOpportunityLineItem,Id,InCurrentHalfYear__c,IsClosed,IsDeleted,IsWon,LastActivityDate,LastModifiedById,LastModifiedDate\
FROM Opportunity where createddate=last_n_days:1
SELECT AccountId,Amount,CampaignId,CloseDate,CreatedById,CreatedDate,Description,Fiscal,FiscalQuarter,FiscalYear,ForecastCategory,ForecastCategoryName,\
HasOpportunityLineItem,Id,InCurrentHalfYear__c,IsClosed,IsDeleted,IsWon,LastActivityDate,LastModifiedById,LastModifiedDate\
FROM Opportunity where createddate=last_n_days:1
Please try this,
DateTime timeNow = System.now(); // Get the time now
DateTime X30MinutesAgo = timeNow.addMinutes(-30); // Subtract 30 minutes from it
System.DEBUG([SELECT ID FROM Account WHERE createdDate <:timeNow AND createdDate >:X30MinutesAgo]);
It will return you records cfreated within 30 minutes.
// OR
Select a.Id From Account a Where a.CreatedDate = TODAY AND HOUR_IN_DAY(a.CreatedDate) > 1
It will return the data which is created within 1 hr.
Please let me know if this help.
Thanks
Shivdeep
Select a.Id,a.createddate,a.lastmodifieddate From opportunity a Where a.lastmodifiedDate = LAST_N_DAYS:4 AND HOUR_IN_DAY(a.lastmodifieddate) <7 order by a.createddate
Add one more AND which is like a.lastmodifieddate <> TODAY.
Thanks !