如何使用SQL Server以dd / mm / yyyy格式显示日期 [英] How show the date in dd/mm/yyyy format using SQL server

查看:171
本文介绍了如何使用SQL Server以dd / mm / yyyy格式显示日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下



String strConnString = ConfigurationManager.ConnectionStrings [ConnectionStrings] .ConnectionString;

SqlConnection con = new SqlConnection (strConnString);

SqlCommand cmd = new SqlCommand(select transaction a.slip_date,a.transaction_id,a.transaction_item_type_id,a.product,a.unit_id from transactionitem,con);

con.Open();

SqlDataAdapter da = new SqlDataAdapter();

DataSet ds = new DataSet();

da.SelectCommand = cmd;

da.Fill(ds);

grdRpt.DataSource = ds;

grdRpt.DataBind();



当我在gridview记录中运行以上内容时如下



slip_Date transaction_id transactionitemtype product unitid


1/6/2018 12:22:00 AM 1 100 000006678 A 3

1/6/2018 12:22:00 AM 2 100000007899 B 2





但是在gridview中我想要了解如下



slip_Date transaction_id transactionitemtype product unitid



1/6 / 2018 1 100000006678 A 3

1/6/2018 2 100000007899 B 2



来自我上面的选择查询我必须做出哪些更改。



我的尝试:



String strConnString = ConfigurationManager.ConnectionStrings [ConnectionStrings] .ConnectionString;

SqlConnection con = new SqlConnection(strConnString);

SqlCommand cmd = new SqlCommand(select distinct a.slip_date,a.transaction_id, a.transaction_item_type_id,a.product,a.unit_id来自transactionitem,con);

con.Open() ;

SqlDataAdapter da = new SqlDataAdapter();

DataSet ds = new DataSet();

da.SelectCommand = cmd;

da.Fill(ds);

grdRpt.DataSource = ds;

grdRpt.DataBind();



当我在gridview记录中运行以上内容时如下



slip_Date transaction_id transactionitemtype product unitid



1/6/2018 12:22:00 AM 1 100000006678 A 3

1/6/2018 12:22:00 AM 2 100000007899 B 2





但是在gridview我想要的更新如下



slip_Date transaction_id transactionitemtype product unitid



1/6/2018 1 100000006678 A 3

1/6/2018 2 100000007899 B 2



来自我上面的选择查询我必须做出哪些更改。

My code as follows

String strConnString = ConfigurationManager.ConnectionStrings["ConnectionStrings"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand("select distinct a.slip_date,a.transaction_id,a.transaction_item_type_id,a.product,a.unit_id from transactionitem", con);
con.Open();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = cmd;
da.Fill(ds);
grdRpt.DataSource = ds;
grdRpt.DataBind();

when i run the above in gridview records as follows

slip_Date transaction_id transactionitemtype product unitid

1/6/2018 12:22:00 AM 1 100000006678 A 3
1/6/2018 12:22:00 AM 2 100000007899 B 2


but in the gridview i want slipdate as follows

slip_Date transaction_id transactionitemtype product unitid

1/6/2018 1 100000006678 A 3
1/6/2018 2 100000007899 B 2

from my above select query what changes i have to made.

What I have tried:

String strConnString = ConfigurationManager.ConnectionStrings["ConnectionStrings"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand("select distinct a.slip_date,a.transaction_id,a.transaction_item_type_id,a.product,a.unit_id from transactionitem", con);
con.Open();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = cmd;
da.Fill(ds);
grdRpt.DataSource = ds;
grdRpt.DataBind();

when i run the above in gridview records as follows

slip_Date transaction_id transactionitemtype product unitid

1/6/2018 12:22:00 AM 1 100000006678 A 3
1/6/2018 12:22:00 AM 2 100000007899 B 2


but in the gridview i want slipdate as follows

slip_Date transaction_id transactionitemtype product unitid

1/6/2018 1 100000006678 A 3
1/6/2018 2 100000007899 B 2

from my above select query what changes i have to made.

推荐答案

这不是一个好消息想要在SQL中格式化日期,这实际上是演示软件的功能,因为日期格式应该设置为用户使用的日期格式,而不是软件。



这很容易做到,但确切的方法将取决于您使用的是哪个GridView控件!

以下是Web版本的示例: gridview colum中的日期时间格式ASP.NET论坛 [ ^ ]但是快速谷歌会找到你正在使用的那个的等价物。
It's not a good idea to format dates in SQL, that really is a function of your presentation software as the date format should be set to that used by the user, not your software.

That's easy enough to do, but the exact method will depend on which GridView control you are using!
Here's an example for the web version: DateTime Format in gridview colum | The ASP.NET Forums[^] but a quick google will find the equivelant for the one you are using.


这篇关于如何使用SQL Server以dd / mm / yyyy格式显示日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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