将SQL Server 2012时间(7)格式化为“HH:mm” [英] Format SQL Server 2012 Time(7) to "HH:mm"

查看:418
本文介绍了将SQL Server 2012时间(7)格式化为“HH:mm”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本周的每一天都有 Time(7)列,我想将它格式化为 HH:mm





我尝试使用SQL Server 2012新的 FORMAT 函数,但它只显示 NULL value。





如何格式化 time(7)数据类型以显示为 HH :mm

解决方案

您应始终在表示层中格式化数据。如果您的用户界面无法对TIME数据类型进行格式化,则可以将该值转换为DATETIME,该数据很可能会受到支持。

  SELECT CAST(TimeColumn AS DATETIME)
FROM MyTable


I have Time(7) columns for each day in the week and I want to format it as HH:mm

I tried to use SQL Server 2012 new FORMAT function, but it only shows the NULL value.

How can I format a time(7) datatype to display as HH:mm?

解决方案

You should always format your data in the presentation layer. If there are circumstance where the TIME datatype cannot be formatted by your UI, you can cast the value to a DATETIME which will more than likely be supported.

SELECT CAST(TimeColumn AS DATETIME)
FROM MyTable

这篇关于将SQL Server 2012时间(7)格式化为“HH:mm”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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