How can I convert date and time using ODBC function?
Question:
I need to get ONLY DATE (= date WITHOUT time) using ODBC escape sequence .
However
SELECT
{fn CONVERT(SomeTable.Col_With_DateTime_Value, SQL_DATE)}
FROM SomeTable
returns the column as a date WITH time value.
Is there an ODBC function that I can use to get the date only?
Note:
This is not a duplicate question.
I know it is possible to use the non- ODBC convert function like
CONVERT(char(8), getdate(), 112) AS v112_ISO
CONVERT(char(10), getdate(), 104) AS v104_XML
but I really need an ODBC function for compatibility.
+3
source to share
2 answers
You can use this:
select {fn convert({fn timestampdiff(SQL_TSI_DAY, 0, DatetimeCol)}, SQL_DATE)}
from SomeTable
Works in environments I have for testing (SQL Server 2000-2012).
Update:
Here's another way that I think might be faster than using convert.
select {fn timestampadd(SQL_TSI_DAY, {fn timestampdiff(SQL_TSI_DAY, 0, DatetimeCol)}, 0)}
from SomeTable
+4
source to share