Oracle example:
Select extract (year from sysdate) from dual; // return Current Year
Select extract (month from sysdate) from dual; // return Current Month
Select extract (day from sysdate) from dual; // return Current Day
Select extract (hour from sysdate) from dual; // Error
Select extract (hour from timestamp '2017-10-10 10:10:10 ') from dual; // Correct
Select extract (minute from sysdate) from dual; // Error
Select extract (minute from timestamp '2017-10-10 10:10:10 ') from dual; // Correct
The preceding sections describe how to use the EXTRACT () function. An important part is that extract extracts the year, month, day, And hour parts in different ways.
When the next parameter of FROM in EXTRACT (year from sysdate) is of the date type, you can EXTRACT the YEAR, month, and day. that is to say, when this parameter is of the date type, the year, month, and day can be extracted, but the hour and minute parts cannot be extracted. the extraction time must be followed by a TIMESTAMP and a time character.
Note that in (minute from timestamp '2017-10-10 10:10:10, if '2017-10-10 10:10:10 'is replaced by a date field and converted to a character type, this method is also incorrect.
For example (minute from timestamp to_date (to_char (date type, 'yyyy-MM-DD hh24: mi: ss'), 'yyyy-MM-DD hh24: mi: ss ')), this cannot be executed.
You can use the to_char () function to extract the \ part from the date field. For example, to_char (date type, 'hh24: mi ')