Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 

 View Only
  • 1.  Extract hour:Minute from timestamp

    Posted Fri May 06, 2022 03:47 PM

    Hi!
    How do I do to extract hour:minute from a timestamp of this format:

    2022-04-12T11:30

    I have been able to get hours with (ex 16, 17..) my current formula:

    extract(hour; [Peroptider].[Peroptider].[Tidpunkt] )

    But i want to get the combination of hour and minute (like 16:30, 17:25..) from the timestamp - how do i write my formula to get this?

    We are using Cognos analytics version 11.1.7

    Thank´s in advance



    ------------------------------
    Leif Glaes
    ------------------------------


    #CognosAnalyticswithWatson


  • 2.  RE: Extract hour:Minute from timestamp

    Posted Mon May 09, 2022 02:30 AM
    Hi Leif,

    You can use the following expression:
    cast<your timestamp >,time)

    The result will be hh:mm:ss, hours, minutes and seconds. You will then format this new column with this dialog box:


    Best regards,

    ------------------------------
    Patrick Neveu
    Positive Thinking Company
    ------------------------------



  • 3.  RE: Extract hour:Minute from timestamp

    Posted Mon May 09, 2022 08:24 AM
    Edited by System Admin Fri January 20, 2023 04:16 PM
    Hi Leif,

    Patrick's response is the most efficient, but if that isn't getting what you want, you can just combine two extract functions like this:

    cast(extract(hour; [Peroptider].[Peroptider].[Tidpunkt] ),varchar(2)) + ':' + cast(extract(minute; [Peroptider].[Peroptider].[Tidpunkt] ),varchar(2))

    The cast is needed to convert the number that gets returned from the extract function into a string so you can concatenate it with a colon and the minutes.

    HTH,
    Todd


    ------------------------------
    Todd Schuman
    ------------------------------



  • 4.  RE: Extract hour:Minute from timestamp

    Posted Mon May 09, 2022 09:28 AM
    Edited by System Admin Fri January 20, 2023 04:35 PM
    If data source is SQL-server:
    FORMAT([Peroptider].[Peroptider].[Tidpunkt],'hh:mm')






  • 5.  RE: Extract hour:Minute from timestamp

    Posted Mon May 09, 2022 09:28 AM
    Edited by System Admin Fri January 20, 2023 04:45 PM
    If data source is SQL-server:
    FORMAT([Peroptider].[Peroptider].[Tidpunkt],'hh:mm')




  • 6.  RE: Extract hour:Minute from timestamp

    Posted Mon May 09, 2022 09:48 AM

    Hi Leif,
    Did you try substring( '2022-04-12T11:30', 12,5)
    If it is a real timestamp field it would include the seconds as well. In which case the following will work:

    substring(cast(2022-04-12T11:30:22, varchar(20)), 12, 5)

    Using extract function works, but you need to deal with losing leading 0's, e.g.  09:05 gets converted to 9:5



    ------------------------------
    Kind regards,
    HENK CAZEMIER
    ------------------------------



  • 7.  RE: Extract hour:Minute from timestamp

    Posted Mon May 09, 2022 02:21 PM

    Hi!

     Thank´s, I will try the different suggested solutions 

    What I forgot to write in my question is that I´m using the solution in a Dashboard. I don´t know if that changes your proposed code-solutions?

    I´m trying to get the endtime (how many ends at a certain time) for our surgerys per month, and if I only use hours the result is like this picture below. But I want to catch/get the numbers of surgerys that end following the minutes too, that is to say I want to show how many that ends 16.32, 16.45, 17.12 and so on...



    ------------------------------
    Leif Glaes
    ------------------------------



  • 8.  RE: Extract hour:Minute from timestamp

    Posted Tue May 10, 2022 03:23 AM
    Hi Leif,

    Based on the following samples (created with a data module):

    Note: it is easy to split the time in hour and minute with a data module.
    I've created a calculation with the following expression:
    count(distinct Minute_ for Hour_)
    Change Aggregate to "None".

    Then, if you try a dashboard, you will have:

    Best regards,

    ------------------------------
    Patrick Neveu
    Positive Thinking Company
    ------------------------------



  • 9.  RE: Extract hour:Minute from timestamp

    Posted Mon May 09, 2022 02:37 PM

    Hi!

     

    Thank´s, I will try the different solutions.

    What I forgot to write in my question is that I´m using the solution in a Dashboard. I don´t know if that changes your solutions?

     

    Vänliga hälsningar
    Leif Glaés
    -------------------------------

    Utdata/analys, kommunikationsstöd
    Verksamhetsområde K6 (anestesi, operation, IVA-postop, smärtmottagning)

    Tel: 070-218 56 68
    Skaraborgs Sjukhus Skövde

    541 85 Skövde
    www.vgregion.se/skas