如何从表格列(06:23:23 AM / PM)格式插入或仅选择TIME [英] How can Insert or Select Only TIME from Table's column (06:23:23 AM/PM) format

查看:68
本文介绍了如何从表格列(06:23:23 AM / PM)格式插入或仅选择TIME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用MaskedEditExtender AjaxTools Control如何才能节省时间 - 以这种格式11:23:22 AM / PM我有两列DataType定义为DateTime一个是INTime(09:30:上午12点)和第二个是OUTTime(06:30:12 PM)我如何在商店程序中编写插入查询..帮助

我是sql sevr的启动器和.net

i使用DataType DateTime .....我想我使用Time7而不是datetime

解决方案

试试这个

 选择 正确 CONVERT  VARCHAR  25 ),GETDATE(), 22 ), 11 
- 尝试上面的变量代码,表格下面一个..
选择 正确 CONVERT VARCHAR 25 ),ColumnName, 22 ), 11 来自 TableNamee



假设您的列数据类型是DateTime,而Ms SqlSever的版本是2005或更高版本......

希望这有帮助


请阅读我对该问题的评论。我们无法帮助你写出没有足够信息的SP。



解决方案1由 Raja Sekhar S 非常好,但我会建议将字段的数据类型更改为 time(T-SQL) [ ^ ]。 />


另一种只返回时间部分日期的方法是使用以下查询(不含 RIGHT function):

  SELECT   CONVERT  VARCHAR  25 ),GETDATE(), 114  AS  CurrentTime 





如果如果要将时间值插入表中,则不应将其转换为varchar数据类型。保存原样。要查看它,您始终可以使用 CAST和CONVERT(T-SQL)功能 [ ^ ]。


I am using MaskedEditExtender AjaxTools Control for time in my application how can i save only time-- in this format 11:23:22 AM/PM i have two column DataType is define as DateTime one is INTime (09:30:12 AM) and second one is OUTTime(06:30:12 PM) how can i write Insert query in Store Procedure.. HELP
I am starter with sql sevr and .net
i used DataType DateTime .....I think i use Time7 instead of datetime

解决方案

Try This

Select Right(CONVERT(VARCHAR(25), GETDATE(), 22),11)
--Try above code for variable, Below one for Table..
Select Right(CONVERT(VARCHAR(25), ColumnName, 22),11) from TableNamee


Assuming that your column data type is DateTime and Version of Ms SqlSever is 2005 or above versions...
Hope this helps


Please, read my comment to the question. We can't help you to write SP having not enough information.

Solution 1 by Raja Sekhar S is very good, but i would suggest to change data type of field to time (T-SQL)[^] if your MS SQL Server is 2008 or later.

Another way to return only time part of date is to use below query (without RIGHT function):

SELECT CONVERT(VARCHAR(25), GETDATE(), 114) AS CurrentTime



If you would like to insert time value into table, you shouldn't convert it into varchar data type. Save as it is. To view it, you can always use CAST and CONVERT (T-SQL) functions[^].


这篇关于如何从表格列(06:23:23 AM / PM)格式插入或仅选择TIME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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