使用C#odbc从日期时间中选择时间值或日期值 [英] Select time value or date value from datetime with C# odbc

查看:121
本文介绍了使用C#odbc从日期时间中选择时间值或日期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#system.data.odbc OdbcCommand对象发送的SQL查询.

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

SELECT Calldate 
  FROM calls;

Calldate列是日期时间类型.

The Calldate column is a datetime type.

我希望select语句仅返回值的日期部分. DateValue函数似乎没有任何作用.我希望在提供给OdbcCommand对象的SQL中实现这一目标.

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.

要查询的资源是一个访问mdb文件.

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

推荐答案

鉴于您使用的是SQL Server,则可以转换日期时间

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



select convert(datetime, CallDate, x) from calls

x可以表示不同日期格式的不同符号/数字值.有关所有不同的数值及其输出示例,请参见此链接.

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

编辑(基于OP使用访问而不是SQL Server的事实)

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

您可以使用MS格式功能来格式化任何字符串:

You can format any string using the MS format function:



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

此处提供更多格式选项: http://www.webcheatsheet.com/SQL/access_functions /format.php

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

这篇关于使用C#odbc从日期时间中选择时间值或日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆