Use STR_TO_DATE in sql with year change

89 Views Asked by At

I have this query:

$sql = "SELECT * FROM giorni WHERE punto = '$punto' && STR_TO_DATE(giorno, '%d/%m/%Y') ...

I need to do a similar query for the previous year. How can i do %Y-1?

1

There are 1 best solutions below

4
On BEST ANSWER

You can simply subtract 1 year from the converted date:

... STR_TO_DATE(giorno, '%d/%m/%Y') - INTERVAL 1 YEAR