Advertise with us

System.Data.SqlClient.SqlException(Date_Format)

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?

Last updated:1/25/2014 1:54:53 AM

1 Answers

Pravesh Singh
Pravesh Singh

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