Home > DeveloperSection > Forums > System.Data.SqlClient.SqlException(Date_Format)
lois waisbrooker
lois waisbrooker

Total Post:70

Points:494
Posted on    January-25-2014 1:41 AM

 C# C# 
Ratings:


 1 Reply(s)
 1272  View(s)
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?



Pravesh Singh

Total Post:411

Points:2881
Posted on    January-25-2014 1:54 AM

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';

Don't want to miss updates? Please click the below button!

Follow MindStick