Consult current month birthday in SQL

Asked

Viewed 1,177 times

2

I need to do a birthday consultation this month. But I would like it to be automatic, and I don’t need to type the month. Below is the example I did, typing the month.

Note: my field is dt_nasc (TIMESTAMP).

SELECT * from top_007 where extract(month from dt_nasc)='9'; //referente ao mes 9

Could someone help me?

  • It’s postgres or another bank?

  • 1

    For a conclusive reply it is necessary to inform the SGBD used

  • Is mysql or another database?

2 answers

4

Use the function now() combined with month() to pick up the current month.

SELECT * from top_007 where month(dt_nasc) = month(now())

1

If it is SQL SERVER the command would look like this:

SELECT * from top_007 where MONTH(dt_nasc) = MONTH(GETDATE())
  • I believe that extract is a Mysql function, so the question must actually be about mysql. Unfortunately there are many users who use the [tag:sql] tag to refer to mysql :/ and end up generating these understanding problems.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.