在 Business Objects Desktop Intelligence (BO Deski) 中设置时间跨度的格式

发布于 2024-07-14 23:53:54 字数 153 浏览 7 评论 0原文

以人类可读的形式(例如 1d 5h 2m 13s)格式化给定的秒数(例如 16742 秒)

  • 谁能告诉我如何使用 BO 字段公式
    或者
  • 来自 T-SQL SELECT 语句(其中秒数形式的持续时间来自 SUM 聚合)?

Can anyone tell me how to format a given number of seconds (for example 16742 seconds) in a human readable form (for example 1d 5h 2m 13s)

  • using a BO field formula
    or
  • from within a T-SQL SELECT statement (where the Duration as Seconds is from a SUM aggregate)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哆啦不做梦 2024-07-21 23:53:54

我已经使用 Deski 和四个变量完成了它。
从小时测量开始,创建一些变量,在下面我的年份变量是 vYears,我的月份变量是 vMonths,我的天变量是 vDays,我的小时变量是 vHours。

vYears 使用以下计算:

=Floor(Sum(<Hours Billed by Date Billed>/24)/365.25)

vWeeks 使用以下计算:

=Floor(Sum((Sum(<Hours Billed by Date Billed>/24)/365.25)-<vYears>)*365.25/7)

vDays 使用以下计算:

=Floor(Sum(Sum((Sum(<Hours Billed by Date Billed>/24)/365.25)-<vYears>)*365.25/7-<vWeeks>)*52/24)

vHours 使用以下计算:

=Truncate(Sum((Sum(Sum((Sum(<Hours Billed by Date Billed>/24)/365)-<vYears>)*365/7-<vWeeks>)*52/24-<vDays>)*24) , 2)

I 然后可以通过执行以下操作输出这些变量:

=<vYears>+" Years "+<vWeeks>+" Weeks "+<vDays>+" Days "+<vHours>+" Hours"

如果您需要更多信息,请随时询问。

谢谢,

马特

I have done it using Deski and four variables.
Start of with the hours measure, create some variables, in the following my year variable is vYears, my Month variable is vMonths, my days variable is vDays, and my hours variable is vHours.

vYears uses the following calculation:

=Floor(Sum(<Hours Billed by Date Billed>/24)/365.25)

vWeeks uses the following calculation:

=Floor(Sum((Sum(<Hours Billed by Date Billed>/24)/365.25)-<vYears>)*365.25/7)

vDays uses the following calculation:

=Floor(Sum(Sum((Sum(<Hours Billed by Date Billed>/24)/365.25)-<vYears>)*365.25/7-<vWeeks>)*52/24)

vHours uses the following calculation:

=Truncate(Sum((Sum(Sum((Sum(<Hours Billed by Date Billed>/24)/365)-<vYears>)*365/7-<vWeeks>)*52/24-<vDays>)*24) , 2)

I Then can output these variables by doing the following:

=<vYears>+" Years "+<vWeeks>+" Weeks "+<vDays>+" Days "+<vHours>+" Hours"

If you need further information please dont hesitate in asking.

Thanks,

Matt

喵星人汪星人 2024-07-21 23:53:54

我个人会为此创建一个 TSQL 函数。 以下是您可以改编的示例:

IF(OBJECT_ID('FN_STRING_TO_TIME', 'FN') IS NOT NULL)
    DROP FUNCTION FN_STRING_TO_TIME
GO

CREATE FUNCTION dbo.FN_STRING_TO_TIME( 

    -- Seconds to convert
    @pSeconds   INT
)
RETURNS VARCHAR(12)
---------------------------------------------------------------------------------------
-- Developer:       Linus Brimstedt
-- Date:        2009-03-17
--
-- Function:        Returns the given seconds in H:MM:SS format
--          
-- Output:          String in format H:MM:SS
--          
---------------------------------------------------------------------------------------
BEGIN

-----------------------------
-- Variables
-----------------------------

    DECLARE @output     VARCHAR(30) -- Describe the variables

    DECLARE @minutes    INT
    DECLARE @hours      INT

-----------------------------
-- Implementation
-----------------------------

    SET @minutes = @pSeconds / 60
    SET @pSeconds = @pSeconds % 60

    SET @hours = @minutes / 60
    SET @minutes = @minutes % 60

-----------------------------
-- Return output
-----------------------------
    RETURN  CAST(@hours AS VARCHAR) + ':'
    +   dbo.FN_STRING_LPAD(@minutes, 2, '0') + ':'
    +   dbo.FN_STRING_LPAD(@pSeconds, 2, '0') 
END
GO

-- Test
DECLARE @seconds    INT
,   @got        VARCHAR(12)
,   @expected   VARCHAR(12)

SELECT  @seconds = 67
,   @expected = '0:01:07'
SET @got = dbo.FN_STRING_TO_TIME(@seconds)

IF(@got != @expected)
    RAISERROR('FN_STRING_TO_TIME(%d) returned bad value: Expected: %s, got %s', 11, 11, @seconds, @expected, @got)

SELECT  @seconds = 60 * 60 * 7 + 60 * 14 + 34
,   @expected = '7:14:34'
SET @got = dbo.FN_STRING_TO_TIME(@seconds)

IF(@got != @expected)
    RAISERROR('FN_STRING_TO_TIME(%d) returned bad value: Expected: %s, got %s', 11, 11, @seconds, @expected, @got)

干杯
/升

Personally I would make a TSQL function for this. Below is a sample that you can adapt:

IF(OBJECT_ID('FN_STRING_TO_TIME', 'FN') IS NOT NULL)
    DROP FUNCTION FN_STRING_TO_TIME
GO

CREATE FUNCTION dbo.FN_STRING_TO_TIME( 

    -- Seconds to convert
    @pSeconds   INT
)
RETURNS VARCHAR(12)
---------------------------------------------------------------------------------------
-- Developer:       Linus Brimstedt
-- Date:        2009-03-17
--
-- Function:        Returns the given seconds in H:MM:SS format
--          
-- Output:          String in format H:MM:SS
--          
---------------------------------------------------------------------------------------
BEGIN

-----------------------------
-- Variables
-----------------------------

    DECLARE @output     VARCHAR(30) -- Describe the variables

    DECLARE @minutes    INT
    DECLARE @hours      INT

-----------------------------
-- Implementation
-----------------------------

    SET @minutes = @pSeconds / 60
    SET @pSeconds = @pSeconds % 60

    SET @hours = @minutes / 60
    SET @minutes = @minutes % 60

-----------------------------
-- Return output
-----------------------------
    RETURN  CAST(@hours AS VARCHAR) + ':'
    +   dbo.FN_STRING_LPAD(@minutes, 2, '0') + ':'
    +   dbo.FN_STRING_LPAD(@pSeconds, 2, '0') 
END
GO

-- Test
DECLARE @seconds    INT
,   @got        VARCHAR(12)
,   @expected   VARCHAR(12)

SELECT  @seconds = 67
,   @expected = '0:01:07'
SET @got = dbo.FN_STRING_TO_TIME(@seconds)

IF(@got != @expected)
    RAISERROR('FN_STRING_TO_TIME(%d) returned bad value: Expected: %s, got %s', 11, 11, @seconds, @expected, @got)

SELECT  @seconds = 60 * 60 * 7 + 60 * 14 + 34
,   @expected = '7:14:34'
SET @got = dbo.FN_STRING_TO_TIME(@seconds)

IF(@got != @expected)
    RAISERROR('FN_STRING_TO_TIME(%d) returned bad value: Expected: %s, got %s', 11, 11, @seconds, @expected, @got)

Cheers
/L

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文