Monday, 16 July 2012

Datepart in SQL Server And Oracle

SQL Server DATEPART() Function




Syntax :

DATEPART(datepart,date)
datepartAbbreviation
yearyy, yyyy
quarterqq, q
monthmm, m
dayofyeardy, y
daydd, d
weekwk, ww
weekdaydw, w
hourhh
minutemi, n
secondss, s
millisecondms
microsecondmcs
nanosecondns


Examples :
select

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

No comments:

Post a Comment