我应该使用什么数据类型 [英] What Datatype should I use

查看:92
本文介绍了我应该使用什么数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生您好,
我必须在SQL中的数据库中传递Show Time not date,我使用smalldatetime数据类型作为字段名startTime在数据库中的项目中很好地存在,它正在像这样保存. 1/1/1900 09:30:00如何删除此内容1/1/1900仅数据库应保存09:30:00如果我为此使用datediff,请给我一个提示.

较小格式[/编辑]

Hello sir,
I have to pass Show Time not date in Database in sql I m using smalldatetime datatype for a field name startTime present in my project well in database it is saving like this. 1/1/1900 09:30:00 how to remove this thing 1/1/1900 only database should save 09:30:00 should I use datediff for this Give one Hint please.

Minor Formating[/Edited]

推荐答案

通过转换c onvert(varchar,getdate(),108)
仅使用时间部分 这只会存储日期时间字符串的时间部分
Use only time part by converting convert(varchar,getdate(),108)
this will only store the time portion of your datetime string


使用DateTime数据类型并按如下所示格式化时间

use DateTime data type and format time as follows

string dt = String.Format("{0:HH:MM:SS}", txtDate.Text);


在sql中,为什么不简单地使用varchar类型和
请检查以下示例以节省时间,它可能会对您有所帮助:
In sql why dont you take simply varchar type and
check the following example to save only time, it may help you :
DateTime dt = DateTime.Now;
        string srt= String.Format("{0:T}", dt);


此返回时间仅从日期时间开始为:11:53:08 am
有关更多信息,请参考: http://www.csharp-examples.net/string-format-datetime/ [ ^ ]


this return time only from datetime as: 11:53:08 am
for more refer:http://www.csharp-examples.net/string-format-datetime/[^]


这篇关于我应该使用什么数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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