Datepart in SQL Server And Oracle
SQL Server DATEPART() Function
Syntax :
DATEPART(datepart,date)
datepart | Abbreviation |
---|---|
year | yy, yyyy |
quarter | qq, q |
month | mm, m |
dayofyear | dy, y |
day | dd, d |
week | wk, ww |
weekday | dw, w |
hour | hh |
minute | mi, n |
second | ss, s |
millisecond | ms |
microsecond | mcs |
nanosecond | ns |
Examples :
select
Result : 2012 datepart(yyyy,birth_date) from [Table_name]
SELECT
SELECT TO_NUMBER(TO_CHAR(SYSDATE, 'HH24')) FROM DUAL
SELECT current_timestamp,SYSDATE FROM dual extract(hour FROM current_timestamp) FROM dual
Result : 2012 datepart(yyyy,birth_date) from [Table_name]
Oracle : Alternative for DATEPART() Function
SELECT
SELECT TO_NUMBER(TO_CHAR(SYSDATE, 'HH24')) FROM DUAL
SELECT current_timestamp,SYSDATE FROM dual extract(hour FROM current_timestamp) FROM dual
Comments
Post a Comment