0
Good afternoon! I have a PHP question! I have a code to show all the fields of a table where the date is 2018.
$sql_manutencao = 'SELECT * FROM manutencao WHERE data_trabalho LIKE "2018%" AND cod_utilizador ='.$id;
The code is working perfectly but I would like to make the condition of the 2018 date automatic! But only for the year 2018!
I want somehow the date I put in the LIKE both give for the format dd-mm-yyyy and for the format yyyy-mm-dd but without using LIKE "%2018%"
I also warn that I am not the one running the comic and may be subject to regular changes!
If you need any more information just say that I change the code. Thank you!
What do you mean by "automatic"? Want
data_trabalho
be always2018
? If that’s the case, you could useEQUAL "2018"
instead ofLIKE
.– CypherPotato
What do you mean? I don’t understand your doubt,
– Filipe L. Constante
If it is working perfectly, what do you want to change? What do you mean by "date is automatic but only for 2018"? If it is only for 2018, what would be the "automatic"?
– Woss
I want somehow the date I put in the LIKE both give for the format dd-mm-yyyy and for the format yyyyyy-mm-dd But without using LIKE "%2018%"
– João Simões
But the date in the bank will not always be in the same format?
– Woss
Not really! Who manages the comic is not me! And may be subject to changes regularly!
– João Simões
What is the data type of the data_work field?
– anonimo
Your question is not about PHP but about SQL, could you inform which DBMS? Mysql, Postgresql... If you are one of the previous take a look at the function
YEAR
of Mysql andEXTRACT
postgresql.– fernandosavio
My DBMS is Mysql and the data type of the data_work field is "date"
– João Simões
If the field is date type then use YEAR(your_date) to pick only the year, regardless of whether the display format is day/month/year, month/day/year or year-month-day.
– anonimo
ok! thank you! it was solved!
– João Simões