0

I have a list of Birthdays in my account. I want to display the Birthdays in the current month. For that I need to compare only month from the date field with the current month. To get the current month I am using THIS_MONTH standard field. My Birthday Date is in DD/MM/YYYY format. Please Help.

Also I want to change the date field to YYYY/MM/DD format.

1
2

Usually best to do such filtering directly in the query. SOQL has various date functions available so if you want to pick out all records with a matching month you can use a query of this form (on whatever object holds your data):

Date d = Date.today();
for (Contact c : [
        select Name
        from Contact
        where CALENDAR_MONTH(Birthdate) = :d.month()
        order by Name
        limit 1000
        ]) {
    System.debug(c);
}

On the formatting, it is usual to stick to the default configured for the user via their locale rather than try to change the format. Dates are stored unformatted and converted on presentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.