如何从时间格式表中删除秒

编程入门 行业动态 更新时间:2024-10-26 02:29:04
本文介绍了如何从时间格式表中删除秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好, 我想知道如何从数据库中的返回值中删除第二个。所以不是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.

推荐答案

msdn.microsoft/en-us/library/ms187928.aspx [ ^ ] 这就是你需要知道.... msdn.microsoft/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)

您应该将原始字段返回到您的代码,并让代码指示相关的格式。因此,如果您使用,则在日期时间变量上使用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 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.

更多推荐

如何从时间格式表中删除秒

本文发布于:2023-10-25 18:22:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1527725.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:格式   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!