Search code examples
t-sqlsql-server-2014

'Extract' is not a recognized built-in function name


Extract function is not available in SQL Server 2014? I want to extract year and month form a date or any other. Thanks.


Solution

  • 'Extract' function used in oracle. you can use 'DATEPART' or 'YEAR' or 'Month' or 'Day' for extract date details on sql server. try the following T-sql

    DECLARE @currentDate DATETIME = GETDATE();
    SELECT DATEPART(yyyy, @currentDate);
    SELECT DATEPART(mm, @currentDate);
    SELECT DATEPART(dd, @currentDate);
    
    SELECT YEAR(@currentDate);
    SELECT MONTH(@currentDate);
    SELECT DAY(@currentDate);