Need help to calculate Month in integer into Year and Month

  • Hi,

    I've this,

    declare @t1 table ( Id int primary key, HowManyMonth int);

    insert into @t1(Id, HowManyMonth) values(1, 17);

    insert into @t1(Id, HowManyMonth) values(2, 37);

    How to make it output like this?

    Id | PeriodDisplay
    ------------------------
    1 | 1 Year(s), 5 Month(s)
    2 | 3 Year(s), 1 Month(s)

    Please help

    • This topic was modified 2 years, 10 months ago by  Adelia.
    • This topic was modified 2 years, 10 months ago by  Adelia.
  • So you will want to use modulus %

    so months/12 to get the years then months%12 to get the remainder then you can format it how you like.

  • Thanks. It workable

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply