SAP IQ: Uptime

At some point you will be asked how long your IQ server has been up.

To determine when the IQ server was started issue:

SELECT PROPERTY('StartTime')

Output:

2015-08-14 18:04:53.918

For the number of days, hours, and minutes we can slice and dice like so:

-- Declarations
DECLARE @UPTIME_DAYS INTEGER
DECLARE @UPTIME_HOURS INTEGER
DECLARE @UPTIME_MINUTES INTEGER

-- Populate variables
SELECT DATEDIFF(day, PROPERTY('StartTime'), CURRENT TIMESTAMP) into @UPTIME_DAYS
SELECT DATEDIFF(hour, PROPERTY('StartTime'), CURRENT TIMESTAMP) % 24 into @UPTIME_HOURS
SELECT DATEDIFF(minute, PROPERTY('StartTime'), CURRENT TIMESTAMP) % 60 into @UPTIME_MINUTES

-- OUTPUT
SELECT @UPTIME_DAYS || ' days ' || @UPTIME_HOURS || ' hours ' || @UPTIME_MINUTES || ' minutes '

Output:

132 days 15 hours 40 minutes
Share Button

One Reply to “SAP IQ: Uptime”

  1. Dear Jason,
    Please check the logic related to datediff. It should be datediff minus 1 for days and hours and leave lowest denomination alone:
    — Declarations
    DECLARE @UPTIME_DAYS INTEGER
    DECLARE @UPTIME_HOURS INTEGER
    DECLARE @UPTIME_MINUTES INTEGER

    — Populate variables
    SELECT DATEDIFF(day, PROPERTY(‘StartTime’), CURRENT TIMESTAMP) into @UPTIME_DAYS
    SELECT DATEDIFF(hour, PROPERTY(‘StartTime’), CURRENT TIMESTAMP) % 24 into @UPTIME_HOURS
    SELECT DATEDIFF(minute, PROPERTY(‘StartTime’), CURRENT TIMESTAMP) % 60 into @UPTIME_MINUTES

    — OUTPUT
    SELECT @UPTIME_DAYS – 1 || ‘ days ‘ || @UPTIME_HOURS – 1 || ‘ hours ‘ || @UPTIME_MINUTES || ‘ minutes ‘

Leave a Reply

Your email address will not be published. Required fields are marked *