仅从datetime插入日期到数据库? [英] Insert date only from datetime to database?

查看:142
本文介绍了仅从datetime插入日期到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试将日期输入到我的列类型为日期"的数据库中.但是值是这样的1/15/2011 12:00:00 AM而我只想输入1/15/2011.请指导我该怎么做?

感谢

Hi,
I am trying to enter date into database where my column type is Date. But the value is like this 1/15/2011 12:00:00 AM whereas I just want to enter 1/15/2011. Please guide how can I do that?

thanks

推荐答案



插入到您的表(列名)中的值(转换(varchar(10),您的日期,120)).

希望这对您有帮助...
Hi ,

Insert into yourtable(columnname) values(convert(varchar(10),yourdate,120)).

Hope this helps...




试试这行

Hi,

Try this line

string shdate=DateTime.Now.ToShortDateString();



否则,从数据库中检索日期值,然后切成所需的任何格式.



otherwise retrieve date values from database and then cut into whatever format you want.


您不能-日期始终包含自约定时间开始的时间,它不是日期表示为2011-09-16,这是自某某某"日期(通用协调时间)午夜以来的xxx毫秒间隔.

不用担心-在根据需要格式化显示时,可以掩盖hour:min:sec部分.
You can''t - a Date always contains the time since an agreed moment in time, it isn''t a date in the sense of 2011-09-16, it is a interval in the sense of xxx milliseconds since midnight on "such-and-such" a date, Universal Coordinated Time.

Don''t worry about it - you can mask out the hour:min:sec part when you format it for a display as needed.


这篇关于仅从datetime插入日期到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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