SYSTEM.DATA.SQLCLIENT.SQLEXCEPTION(DATE_FORMAT)

lois waisbrooker

Total Post:70

Points:494
Posted by  lois waisbrooker
C# 
C#
 1662  View(s)
Ratings:
Rate this:

I am using Sql-Server 2012 and have a query              

string sqlQuery = "SELECT distinct DATE_FORMAT(collectiondate,'%m/%d/%Y') FROM reports  where patientid= " + patientId + " and isdeleted=false order by collectiondate desc";

            var lst = Session.CreateSQLQuery(sqlQuery).List();

            ArrayList rpt = new ArrayList();

            rpt.Add("--ALL--");

but I am getting an error

System.Data.SqlClient.SqlException: 'DATE_FORMAT' is not a recognized built-in function name.

Can someone help me out?

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: System.Data.SqlClient.SqlException(Date_Format)

    Hi Lois,

    You can use the FORMAT() command in SQL Server 2012 instead.

    DECLARE @d DATETIME = GETDATE();

    SELECT  FORMAT(@d, 'mm/dd/yy', 'en-US') AS 'Result';

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!