比较Sql Server中的两次Times,使用AM/PM在Sql Server中仅保存时间格式 [英] Compare the two Times in Sql server , Save Only Time Format in Sql server with AM/PM

查看:332
本文介绍了比较Sql Server中的两次Times,使用AM/PM在Sql Server中仅保存时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
1.我只想将时间存储在sqlserver 2008R2中.具有12小时或24小时格式.

2.想在sqlserver2008R2中比较两次.

首先,我使用Varchar类型在表格中保存了时间,例如"10.00AM",
但无法从原始时间比较此字段.

我要检查我的表时间字段"必须小于给定时间".


救救我...


谢谢大家……...

Hi Guys,
1.I want to store only time in sqlserver 2008R2. With 12Hrs or 24Hrs Format.

2.Want to compare the two times in sqlserver2008R2.

First i saved the time in table using Varchar type like this "10.00AM" ,
but can not compare this field from the Original time .

I want check My table Time Field must be less than Greater than the Given Time.


Help Me...


Thanks For all.........

推荐答案

我要检查我的表时间字段"必须小于给定时间". /i>
只需在数据库中使用DateTime类型的字段即可.您需要将日期和时间一起存储.完成后,SQL将在完成后负责所有比较.

希望您能理解,SQL Server仅支持 DATE + TIME 类型的列.
现在,如果您只需要时间,则需要将其提取出来.在此处中查看详细信息> [ ^ ]和类似的讨论 ^ ].

使用Varchar然后进行转换/比较会使事情变得复杂,我建议您使用内置的datetime字段并让SQL处理比较等.
I want check My table Time Field must be less than Greater than the Given Time.
Just use a DateTime type of field in database. You would need to store date along with time. Once done, SQL will take care of all comparisons when done.

Hope you get that, SQL Server only supports DATE + TIME type of column.
Now, in case you need only time then you need to extract that out. See details here[^] and a similar discussion here[^].

Using a Varchar and then converting/comparing would make things complicated and I would suggest you to use the inbuilt datetime field and let SQL handle the comparison, etc.


这篇关于比较Sql Server中的两次Times,使用AM/PM在Sql Server中仅保存时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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