数据库中的时间值 [英] time value in database

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

问题描述

我必须只在textbox中存储数据库。在文本框中我只插入时间。

我必须为此采用什么数据类型?

ex:i enter在文本框中开始时间,这个值存储在database.if其他任何其他ohetthen时间值是尝试输入然后msg接近文本框显示如...无效时间。

i have to store only time in database from textbox.In textbox i insert only time .
what datatype i have to take for this?
ex:i enter start time in textbox and this value is store in database.if anything else ohetthen time value is try enter then msg near textbox display like ...invalid time.

推荐答案

您还没有提到您正在使用的数据库服务器。如果是SQL Server 2008或更高版本,则获得时间 [ ^ ]作为新的数据类型。 (注意:我在这里只考虑了SQL Server .Oracle和其他数据库也可以支持这个开箱即用)。



如果您使用旧版本的SQL,那么你可以将它们存储在 DateTime [ ^ ]或varchar来存储时间。但是你需要在使用时提取时间部分(在db端或你的.net代码中)。



希望它有所帮助!
You haven''t mentioned which database server you are using. If it''s SQL Server 2008 or above, you got time[^] as a new datatype. (Note: I am just considered SQL Server here. Oracle and other db may also support this out of the box).

If you using old versions of SQL, you can either store them in DateTime[^] or varchar to store the time. But you will need to extract the time part (either on db side or your .net code) while using it.

Hope it helps!


当处理数据库中的仅时间字段时,我通常将它们作为十进制存储在数据库中,并使用TimeSpan对象使用TimeSpan.TotalMilliseconds属性在我的应用程序中处理它们。
When dealing with Time only fields in a database, I usually store them as decimal in the database and use the TimeSpan object to handle them in my applications using the TimeSpan.TotalMilliseconds property.


您应该在数据库中使用 Datetime 数据类型。



谢谢
You should take Datetime datatype in your database.

Thanks


这篇关于数据库中的时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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