[SalesForce] Marketing Cloud SQL Birthday date (smalldatetime) is equal to today

i am trying to filter with a SQL query a data extension. I tried to get the people in de DE which have their birthday today. The format of the birthday field is i think smalldatetime. This is how it looks like "4/6/1980 12:00:00 AM".

If i try something like:

select convert(date, contact.Birthdate) as Birthday
from Contact_Salesforce contact
where contact.Birthdate = GetDate()

It provides 0 results because the contact.Birthdate outputs smalldatetime as a value like this: "4/6/1980 12:00:00 AM". Can someone help me with this?

Best Answer

To make a comparison on equally formatted values, try something like this:

select convert(date, contact.Birthdate) as Birthday
from Contact_Salesforce contact
where CONVERT(date, contact.Birthdate) = CONVERT(date, GetDate())

This should match them on the MM/dd/yyyy format (e.g. 04/24/2018) instead of potentially comparing apples to oranges due to format differences.


EDIT - As @AnonWonderer stated, I believe it is the year that is throwing it off.

Try below instead:

select convert(date, contact.Birthdate) as Birthday
from Contact_Salesforce contact
where DATEPART("month", contact.Birthdate) = DATEPART("month", GetDate())
AND DATEPART("day", contact.Birthdate) = DATEPART("day", GetDate())
Related Topic