您的位置:程序门 -> .net技术 -> c#



如何更改sql server 2005 的默认时间格式


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何更改sql server 2005 的默认时间格式[已结贴,结贴人:civilman]
发表于:2007-05-23 20:08:35 楼主
sql中默认的格式是月日年,而vs中得到的日期格式为年月日,
结果我用
  system.datetime.now.tostring(   )
更新到sql中的日期型数据,   日期就不对了.
请问,sql中该如何修改,才能更改它的默认时间格式.
发表于:2007-05-23 20:29:221楼 得分:0
--   set   date   format   to   month,   day,   year.
set   dateformat   mdy;
go
declare   @datevar   datetime;
set   @datevar   =   '12/31/1998 ';
select   @datevar   as   datevar;
go

--   set   date   format   to   year,   day,   month.
set   dateformat   ydm;
go
declare   @datevar   datetime;
set   @datevar   =   '1998/31/12 ';
select   @datevar   as   datevar;
go

--   set   date   format   to   year,   month,   day.
set   dateformat   ymd;
go
declare   @datevar   datetime;
set   @datevar   =   '1998/12/31 ';
select   @datevar   as   datevar;
go
发表于:2007-05-23 20:30:262楼 得分:20
1   取值后格式化
{0:d}小型:如2005-5-6
{0:d}大型:如2005年5月6日
{0:f}完整型

2   当前时间获取  
datetime.now.toshortdatestring

3   取值中格式化
sql   server里面可能经常会用到的日期格式转换方法:

举例如下:

select   convert(varchar,   getdate(),   120   )
2004-09-12   11:06:08

select   replace(replace(replace(convert(varchar,   getdate(),   120   ), '- ', ' '), '   ', ' '), ': ', ' ')
20040912110608

select   convert(varchar(12)   ,   getdate(),   111   )
2004/09/12

select   convert(varchar(12)   ,   getdate(),   112   )
20040912

select   convert(varchar(12)   ,   getdate(),   102   )
2004.09.12

其它我不常用的日期格式转换方法:

select   convert(varchar(12)   ,   getdate(),   101   )
09/12/2004

select   convert(varchar(12)   ,   getdate(),   103   )
12/09/2004

select   convert(varchar(12)   ,   getdate(),   104   )
12.09.2004

select   convert(varchar(12)   ,   getdate(),   105   )
12-09-2004

select   convert(varchar(12)   ,   getdate(),   106   )
12   09   2004

select   convert(varchar(12)   ,   getdate(),   107   )
09   12,   2004

select   convert(varchar(12)   ,   getdate(),   108   )
11:06:08

select   convert(varchar(12)   ,   getdate(),   109   )
09   12   2004   1

select   convert(varchar(12)   ,   getdate(),   110   )
09-12-2004

select   convert(varchar(12)   ,   getdate(),   113   )
12   09   2004   1

select   convert(varchar(12)   ,   getdate(),   114   )
11:06:08.177

//string处理
string.tostring( "0.00 ")
string.format( "{0:n2} ",string)

//绑定处理
<asp:boundcolumn   datafield= "totalprice "   headertext= "小计(元) "   dataformatstring= "{0:c} "> </asp:boundcolumn>

<itemtemplate> <#   databinder.eval(container.dataitem,   "order_totalpri ", "{0:c} ")   %> </itemtemplate>

//对价格进行四舍五入
string   myprice   =   string.format( "{0:n2} ",   math.round((convert.todouble(price)*convert.todouble(discount)*0.1),2));

datagrid
{0:0.0}
发表于:2007-05-23 20:31:083楼 得分:0
晕 发多了 没注意 中间那部份是  你自己看吧


快速检索

最新资讯
热门点击