SQL rule to filter only one month in TIMESTAMP field

Asked

Viewed 152 times

0

Hello. I have a stock drive in month 1, month 2, month 3, month 4, month 5... how do I create rule for appearing only stock drives in month 3? Remembering that the field is TIMESTAMP.

1 answer

1

There are many ways to do it.

Some examples:

Using BETWEEN to pull a break:

SELECT *
FROM tabela
WHERE timestamp BETWEEN '01/03/2018 00:00:00' AND '31/03/2018 23:59:59'

Using MONTH to filter only the month:

SELECT *
FROM tabela
WHERE MONTH(timestamp) = 3

Using MONTH and YEAR to filter month and year:

SELECT *
FROM tabela
WHERE MONTH(timestamp) = 3
AND YEAR(timestamp) IN (2017,2018)

Very good and complete documentation: Date and Time Functions - Mysql

  • 1

    Hello. Great!!! I believe that the first form will serve. Thank you and!!

  • @Wagner if the answer solved, mark as correct

Browser other questions tagged

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