如何使用C#在SQL数据库中仅保存时间 [英] How to save only time in SQL databse using C#
本文介绍了如何使用C#在SQL数据库中仅保存时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请任何人告诉我如何使用c#在sql server 2014中只保存时间。我使用存储过程来节省时间
也解释了数据库表中Time属性的最佳数据类型。
将来我会利用这段时间搜索数据。
哪一个最适合节省时间使用文本框或日期时间选择器哪个最适合从用户那里获取时间。
请解释一下。
谢谢提前
我尝试过的事情:
i不知道怎么样我可以这样做吗
hi please any one tell me how cann i save only time in sql server 2014 by using c#. i used store procedure for saving time
also explain me what is best datatype for Time attribute in database table.
In future i use this time for searching data.
and which one is best for save time using text box or datetime picker which one is best for getting time from user .
please explain this.
Thanks in advance
What I have tried:
i have no idea how can i do this
推荐答案
有一种TIME数据类型: time(Transact-SQL)| Microsoft Docs [ ^ ]但是......在将它发送到SQL之前将其转换为UTC作为你的DateTime值的一部分 - 如果你没有,那么你将使用当地时间可能是一个真正的问题 - 它对于不同国家的两个用户有所不同,并且不会注意到夏令时。
就个人而言,我是建议将其作为UTC日期和时间存储在DATETIME2列中,并根据需要提取时间 - 这使得比较在许多方面变得更加简单。
There is a TIME datatype: time (Transact-SQL) | Microsoft Docs[^] but ... convert it to UTC as part of your DateTime value in C# before you send it to SQL - if you don't, then you will be using local time which can be a real problem - it differs for two users in different countries, and it takes no notice of daylight savings.
Personally, I'd recommend storing it as a UTC date and time in a DATETIME2 column, and extract times as necessary - it makes comparisons a lot simpler in many ways.
这篇关于如何使用C#在SQL数据库中仅保存时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文