ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

SQL DB2 get week number for difference between 2 dates

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SQL DB2 get week number for difference between 2 dates

    I am trying to get week number for current year from the difference of 2 dates, is this possible? I know the WEEK function only takes one date/timestamp trying to find a workaround, maybe theres a way to use days function to get back to the week number, these are what I tried originally
    Code:
    select week(current_Date - (current_date - 100 days)) as week_num
    from sysibm.sysdummy1
    select days(current_Date) - days('2025-10-01') as days_between
    from sysibm.sysdummy1​
    Golf is a game in which you yell "fore," shoot six, and write down five.

  • #2
    Hi kast,

    I don't know if I understand your question.

    Do you know the timestamp_diff funcion?

    look here:

    The TIMESTAMPDIFF function returns an estimated number of intervals of the type defined by the first argument, based on the difference between two timestamps.


    here's my example:

    this is the difference in week between today and the first of march

    Code:
    values (TIMESTAMPDIFF(32, CHAR((current_timestamp ) - TIMESTAMP('2025-03-01-00.00.00') ) ) );
    ​

    Comment


    • kast1
      kast1 commented
      Editing a comment
      thanks I'll try this
Working...
X