在SQL Server 2012中将时间转换为十进制 [英] convert time to decimal in SQL server 2012
问题描述
我在sql server 2012中有一个表,其列之一具有以下时间数据类型的数据,
如何将00:45:00转换为0.45
或01:45:00到1.45?
i have a table in sql server 2012, with one of its column having the following data in time datatype, How would you convert 00:45:00 to 0.45 or 01:45:00 to 1.45 ?
请帮助。
推荐答案
从问题上看,您似乎只想用'。'删除':'。如果是这样,则可以在sql server 2012中以多种方式实现。下面是一个示例。
From the question, it seems you only want to remove the ':' with '.'. If so, it can be achieved in many ways in sql server 2012. One example is below.
如果您的列为 Datetime,请使用:
SELECT REPLACE(LEFT(CAST(DatetimeCol AS TIME),5),':',',')FROM Tbl
If your column is 'Datetime', use this: SELECT REPLACE(LEFT(CAST(DatetimeCol AS TIME),5),':',',') FROM Tbl
否则,如果只是'Time',则删除
Else if it just 'Time' then remove the casting.
这篇关于在SQL Server 2012中将时间转换为十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!