如何从时间格式表中删除秒 [英] How Do I Remove The Seconds From Time Format Table

查看:246
本文介绍了如何从时间格式表中删除秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我想知道如何从数据库中的返回值中删除第二个。所以不是HH:MM:SS,我想要HH:MM。使用SELECT查询表时如何实现这一点?



非常感谢。

Hello,

I would like to know how I can remove the second from a return value in database. So instead of HH:MM:SS, I would like HH:MM. how do I achieve this when querying the table using SELECT?

Thanks a lot.

推荐答案

https://msdn.microsoft.com/en-us/library/ms187928.aspx [ ^ ]



这就是你需要知道....
https://msdn.microsoft.com/en-us/library/ms187928.aspx[^]

This is what you need to know....


继续解决方案1 ​​ - 遗憾的是没有开箱即用的格式可以为你做,你还需要substring [ ^ ]



例如
Further to solution 1 - unfortunately there is no out-of-the box format that will do that for you, you will also need substring[^]

e.g.
-- Data is a DateTime column
select SUBSTRING(CONVERT(varchar(30), GETDATE(), 121), 1, 16)




or

-- Data is a Time column
DECLARE @T AS TIME = '10:57:43'
select SUBSTRING(CONVERT(varchar(30), @T, 121),1,5)


您应该将原始字段返回到您的代码,并让代码指示相关的格式。因此,如果您使用.net,则在日期时间变量上使用ToString(XYZ),其中XYZ是您选择的格式。您应该将显示和格式问题留给表示层,数据库不应该做出这些决定。
You should return the original field to your code and have the code dictate the relevant format. So if you're using .net then use ToString("XYZ") on your datetime variable where XYZ is the format of your choice. You should leave matters of display and formatting to your presentation layer, the database shouldn't be making these decisions.


这篇关于如何从时间格式表中删除秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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