Page 1 of 1
Fetching only year from mysql timestamp date
Posted: Tue Feb 03, 2004 4:35 am
by apek
how to fetch only year from mysql database??and the data type is timestamp???
Code: Select all
Select * from repairbreakdown WHERE noTag = '{$_POST["noTag"]}' and year(waktuTamat) = '{$_POST["year"]}'"
is my code correct????
i use year(waktuTamat)...is this true?
Posted: Tue Feb 03, 2004 4:55 am
by twigletmac
If you only want to fetch the year then you can use YEAR() to specify it in the SELECT statement:
Code: Select all
SELECT field1, field2, field3, YEAR(date_field) AS date_field_year FROM table
It is good practise to specify which fields you wish to return from the table. It is also a good idea to not put user inputted data directly into a query without validating it first.
If you are unsure whether your code is correct does that mean that it is not doing what you expect?
Mac
Posted: Tue Feb 03, 2004 5:17 am
by apek
but can i use that to fetch year from timestamp data type???
Posted: Tue Feb 03, 2004 7:24 am
by apek
hello????
Posted: Tue Feb 03, 2004 9:09 am
by twigletmac
Have you tried it?
Mac