System.Data.SqlClient.SqlException(Date_Format)

Total Post:70

Points:494

C# 
C#
 2206  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. 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';

      Modified On Apr-04-2018 01:52:36 AM

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.