0

The code I'm using works until December.

Select * FROM [Date_Extension]
WHERE month(birthday) = month(getdate()) + 1

How do I add a CASE statement into this to select January when month(getdate()) + 1 = 13? Or should I be doing this a different way all together?

2 Answers 2

3

Why not try a DatePart with the DateAdd?

SELECT * FROM [Data Extension] WHERE
DATEPART(mm,birthday) = DATEPART(mm,(DateAdd(m,1,GetDate()))

This will take the recipient's birthday month and match it to the following month

1
  • Thanks! This is great. I'm somewhat new to sql and learning on the go. Appreciate the help.
    – Gary
    Mar 27, 2018 at 19:03
0

Try this code:

Option 1:-If you "birthday" field set as DATE varchar

SELECT *, MONTH(STR_TO_DATE(dob, '%d-%m-%Y')) as Month FROM users WHERE MONTH(STR_TO_DATE(dob, '%d-%m-%Y')) = MONTH(DATE_ADD(NOW(), INTERVAL + 30 DAY))

Option 2:- If you "birthday" field set as DATE datatype

SELECT *, MONTH(dob) as Month FROM user WHERE MONTH(dob) = MONTH(DATE_ADD(NOW(), INTERVAL + 30 DAY))

You must log in to answer this question.

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