DB2: Round timestamp to 29 mins

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • garg1984
    New Member
    • Jun 2014
    • 1

    DB2: Round timestamp to 29 mins

    Hi - Can I round timestamp to next 29 mins ?

    For instance -

    If current date is : 2014-06-20 10:29:00.000000 , can i round it to 2014-06-20 10:00:00.000000 ?

    Thanks,
    Sid
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    TRUNC_TIMESTAMP scalar function

    Read syntax diagramSkip visual syntax diagram
    .-,--'DD'---------------------------.
    >>-TRUNC_TIMESTAMP--(--expression--+-----------------------------------+--)-><
    '-,--format-string--+-------------+-'
    '-locale-name-'

    The schema is SYSIBM.

    The TRUNC_TIMESTAMP scalar function returns a TIMESTAMP that is the expression truncated to the unit specified by the format-string. If format-string is not specified, expression is truncated to the nearest day, as if 'DD' was specified for format-string.

    Code:
    SELECT TRUNC_TIMESTAMP(current time,"HH")  ....
    Last edited by Luuk; Jun 21 '14, 07:54 AM. Reason: untested!

    Comment

    • Anas Mosaad
      New Member
      • Jan 2013
      • 185

      #3
      Code:
      db2 "select trunc_timestamp(current timestamp + cast((30  + extract(second from current timestamp))/ 60 as int) minutes, 'minute'), current timestamp from sysibm.sysdummy1"

      Comment

      Working...