Select time value or date value from datetime with C# odbc

佐手、 提交于 2020-01-05 17:19:16

问题


I have a SQL query being sent by C# system.data.odbc OdbcCommand object.

SELECT Calldate 
  FROM calls;

The Calldate column is a datetime type.

I want the select statement to only return the date portion of the value. The DateValue function doesn't seem to do anything. I am hoping to achieve this within the SQL provided to the OdbcCommand object.

Edit 1: The resource being queried is an access mdb file.


回答1:


Given you are using sql server, you can convert the datetime


select convert(datetime, CallDate, x) from calls

x can represent different notations/numeric values for different date formatting. See this link for all the different numeric values, and the examples of their output.

http://linesofcode.net/snippets/45

EDIT (based on the fact that OP is using access, not SQL server)

You can format any string using the MS format function:


SELECT Format(CallDate,'yyyy/mm/dd') FROM calls

more formatting options here: http://www.webcheatsheet.com/SQL/access_functions/format.php




回答2:


How about -

select datevalue(Calldate) from calls;

Other functions listed here



来源:https://stackoverflow.com/questions/5865066/select-time-value-or-date-value-from-datetime-with-c-sharp-odbc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!