Hello. I have a stock drive in month 1, month 2, month 3, month 4, month 5 ... how do I create the rule for only the stock movements to appear in month 3? Remember that the field is TIMESTAMP.
Hello. I have a stock drive in month 1, month 2, month 3, month 4, month 5 ... how do I create the rule for only the stock movements to appear in month 3? Remember that the field is TIMESTAMP.
There are several ways to do it. Some of them:
Using BETWEEN
to pull a range:
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