Assuming that you're doing this on something other than Marketing Cloud...
What you have here isn't a date, it's a datetime. While there are SOQL Date functions that can help, their primary use is in filters (i.e. the WHERE
clause) and you can't compare the result of a Date function with a Date literal like TODAY
or THIS_YEAR
. In general, you can't change the type of a field that you get back in the result of a query.
In Apex, the Datetime class does have methods that can extract the Date portion (e.g. date()
, see the Datetime documentation for more information) as well as methods to extract the month and day.
While you can use Apex to further refine the results of a query, what you're looking to sounds like it's simple enough that you could use the 'ol formula field workaround. That is, you can't create the filter directly in a query, but you can create a formula field that does. You'd then use that formula field in your query.
Something like
AND(
MONTH(My_Datetime_Field__c) = MONTH(TODAY()),
DAY(My_Datetime_Field__c) = DAY(TODAY())
)
Your formula should return a boolean value. Assuming it's named Month_And_Day_Matches__c
, your query would end up looking like
[SELECT Id FROM MyObject__c WHERE Month_And_Day_Matches__c = true]