Welcome Guest, Not a member yet? Register   Sign In
Active Record Select Statement with DATEADD
#1

[eluser]whobutsb[/eluser]
Hello there,

I'm working on creating a MSSQL query with Active Record and i'm trying to select a datetime column but output only the date without the time.

So in my CI model I have this statement:

Code:
$this->db->select("DATEADD(dd, 0, DATEDIFF(dd, 0, dbo.tblSurveySession.surveyCompleted)) AS answerDate", FALSE);

But my output error the select statement looks like this:
Code:
SELECT ... DATEADD, dd, 0, DATEDIFF(dd, 0, dbo.tblSurveySession.surveyCompleted), AS answerDate ...

What it should look like is this:
Code:
DATEADD(dd, 0, DATEDIFF(dd, 0, dbo.tblSurveySession.surveyCompleted)) AS answerDate

The CI select statement is breaking up the SELECT statement with commas.
I could write my query with the $this->db->query($sql) method but I think its easier to maintain and read with CIs AR.

Any thoughts?

Thanks for the help!




Theme © iAndrew 2016 - Forum software by © MyBB