Select with YEAR and MONTH together

4

Is it possible to combine the year and the month together, and to pass the 20017-06 to the select?

SELECT SUM(valor) FROM contas where YEAR(data) = '2017' and MONTH(data) = '06'
    
asked by anonymous 06.06.2017 / 00:21

1 answer

3

If possible, use the date_format() function by passing the desired format instead of the two functions. Y for the year with 4 digits and m for the month with two digits.

SELECT SUM(valor) FROM contas where date_format(data, '%Y-%m') = '2017-07'
    
06.06.2017 / 00:26