In account record I have a custom myDate__c field of type date.

I need to retrieve all Account records where myDate__c is older than 45 days.

I've tried with the following query:

SELECT id, name 
FROM Account 
WHERE myDate__c <= today() - 45

However I received a warning message:

Date and number are incompatible types

How to change my query to retrieve the correct Account records?

I need only SOQL. No Apex.

1 Answer 1


I recommend you read up on Date Formats and Date Literals in the SOQL and SOSL Reference. This resource covers several ways you can format date fields that you may find useful in the future. Specifically for your current use case:

Date Literal

For the number n provided, starts 00:00:00 of the current day and continues for the past n days.

SELECT Id FROM Account WHERE CreatedDate = LAST_N_DAYS:365

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .