如何使用ODBC函数将日期时间转换为日期? [英] Howto convert datetime to date with an ODBC function?
问题描述
问题:
我只需要使用ODBC转义序列来获得DATE(=日期,没有时间).
I need to get the DATE ONLY (= date WITHOUT time) with an ODBC escape sequence.
但是
SELECT
{fn CONVERT(SomeTable.Col_With_DateTime_Value, SQL_DATE)}
FROM SomeTable
确实将列作为datetime值(带日期的日期)返回.
does return the column as datetime value (date WITH time).
是否可以使用任何 ODBC函数来获取日期值(仅 ?
Is there any ODBC function I can use to get the date value only ?
注意:
这不是重复的问题.
我知道可以使用 non -ODBC转换功能,例如
Note:
This is not a duplicate question.
I know one can use the non-ODBC convert function, like
CONVERT(char(8), getdate(), 112) AS v112_ISO
CONVERT(char(10), getdate(), 104) AS v104_XML
但出于兼容性原因,我确实需要 ODBC 函数.
but I really need an ODBC function for compatibility reasons.
推荐答案
您可以使用:
select {fn convert({fn timestampdiff(SQL_TSI_DAY, 0, DatetimeCol)}, SQL_DATE)}
from SomeTable
可以在我可以测试的环境中工作(SQL Server 2000-2012).
Works in the environments I have available to test on (SQL Server 2000-2012).
更新:
我认为这是比使用convert更快的另一种方式.
Here is another way that I believe could be faster than using convert.
select {fn timestampadd(SQL_TSI_DAY, {fn timestampdiff(SQL_TSI_DAY, 0, DatetimeCol)}, 0)}
from SomeTable
这篇关于如何使用ODBC函数将日期时间转换为日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!