SQL Server中的日期字段 [英] Date Field in Sql server
本文介绍了SQL Server中的日期字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在sql表和sql management studio中定义一个Date字段.
日期存储如下:
I define a Date field in my sql table and in sql management studio
dates store like this :
1390-10-14
我通过遮罩0000/00/00使用遮罩的文本框
但是在我的datagrid c#中,显示如下:
i use a masked textbox by mask 0000/00/00
but in my datagrid c# this is show like:
14/10/1390
当我使用代码
and when i use the code
maskedtxt.text=datefield.tostring();
出现在上面的文本框中.
appear in textbox like above.
what''s code need to correct this?
推荐答案
尝试此操作
try this
string dttime = "12-31-2011 10:30:00";
DateTime dt = Convert.ToDateTime(dttime);
string dttime=dt.Date.ToString("yyyy/MM/dd");
我更喜欢将波斯日期存储为string
在数据库中.
我将其用于表示层(UI).
但是我在C#中使用了用户定义的方法,将string
转换为System.Globalization.PersianCalendar
用于业务层和一些计算.
I prefer to store persian dates asstring
in database.
I utilize it for Presentation Layer (UI).
But I use an user defined method in C# to convertstring
toSystem.Globalization.PersianCalendar
for Business Layer and some calculations.
这篇关于SQL Server中的日期字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文