SqlServer数据库的问题,表列Datetime [英] problem with SqlServer database , table column Datetime

查看:73
本文介绍了SqlServer数据库的问题,表列Datetime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我正在使用Asp.Net,C#,SqlServer 2005.



我在SqlServer 2005 DataBase中有一个表。



在这个表中我有一个列名DateValidFrom,数据类型为(Datetime),当我用Query运行这个表时列显示为

2013-01-15 00:00:00.000



当我将此数据库表加载到asp.net Gridview时显示与2013-01-15 00:00:00.000相同但我不需要时间我需要这样的格式2013/01/15。



请帮忙。谢谢。

Dear Friends,

am working on Asp.Net, C#, SqlServer 2005.

I have a Table in SqlServer 2005 DataBase.

In this Table i have a column name DateValidFrom with Data Type as (Datetime) and when i run this table with Query the column displays as
2013-01-15 00:00:00.000

and When i load this database table to asp.net Gridview it is displaying same as 2013-01-15 00:00:00.000 But I dont need time Just I need like this format 2013/01/15.

Please help. thanks.

推荐答案

选择数据时请尝试以下查询。

Try the below query when selecting the data.
SELECT CONVERT(char(10), GetDate(), 111) --2013/01/15



用列名替换GetDate()。



谢谢...


Replace GetDate() with the Column Name.

Thanks...


将Date带入DateTime属性或变量,并在C#代码中使用datetime的ToShortDateString()方法,或者您可以使用以下命令将日期转换为shortdate: -

Take the Date into a DateTime property or variable and use ToShortDateString() method of datetime in your C# code OR at you can convert the date to shortdate using :-
Select Convert(VarChar, GetDate(), 101)





谢谢,



Thanks,


尝试将日期格式化为如下所示

Try formating the date as shown below
SELECT REPLACE(convert(varchar, getdate(), 102),'.','/') --2013/01/15





参考

SQL Server日期格式 [ ^ ]

如何设置日期时间和格式Sql Server中的日期 [ ^ ]


这篇关于SqlServer数据库的问题,表列Datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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