本文介绍了DateTime字符串分隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以建议以下解决方案吗?

在sql table列中,我将字段定义为DATETIME.
在检索我只想约会的时候.
我的项目在ASP.net中,C#;

我正在网格中显示数据.

公共数据表load_Project()
{

DataTable dtTower = new DataTable();
字符串sql =从tbl_Project中选择projName";
SqlCommand cmd =新的SqlCommand(sql,con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter sda =新的SqlDataAdapter(cmd);

sda.Fill(dtTower);
返回dtTower;

}

can anybody suggest any solution for the below:

In sql table column, I defined a field as DATETIME.
while retrieving I want on only date.
And my project is in ASP.net, C#;

And I am displaying data in grid.

public DataTable load_Project()
{

DataTable dtTower = new DataTable();
string sql = "select projName from tbl_Project";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter sda = new SqlDataAdapter(cmd);

sda.Fill(dtTower);
return dtTower;

}

推荐答案



shanawazway写道:
shanawazway wrote:

字符串sql =从tbl_Project中选择projName";

string sql = "select projName from tbl_Project";



将您的SQL查询更改为

select projName, convert(varchar,dateField,101) from tbl_Project
(其中dateField是您在数据库中的日期字段).

101将以mm/dd/yyyy格式返回您的日期,但还有其他可用格式(请查看msdn上的Convert关键字以获取其他格式).



Change your sql query to

select projName, convert(varchar,dateField,101) from tbl_Project
(where dateField is your date field in the database).

101 will return your date in mm/dd/yyyy format but there are other formats available as well (check out the Convert keyword on msdn for other formats).


这篇关于DateTime字符串分隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 15:38