Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. how to convert an integer to days months years

how to convert an integer to days months years

Scheduled Pinned Locked Moved Database
helptutorial
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ahmad_yossef
    wrote on last edited by
    #1

    how to convert an integer to days months years i have a number of days resulted from sum of datediff to many rows as integer i want to convert this days into days months years like this pr start end days_diff ------------------------------------------------------- 237 2010-06-01 2010-11-30 182 237 2010-12-01 2011-05-31 181 237 2011-06-01 2012-05-31 365 237 2012-06-01 2013-05-31 364 237 2013-06-01 2014-05-31 364 this total a 1456 days i want to convert this days into 4 years 0 months 1 days when i use the regular sum for each record into days months years it creates 3 years 12 months 1 days or any way that produce the same result even not by calculate the sum of the days difference but produce the same result 4 years 0 months 1 days not 3 years 12 months 1 days thanks for help Lost & Forgotten

    Kornfeld Eliyahu PeterK L Richard DeemingR 3 Replies Last reply
    0
    • A ahmad_yossef

      how to convert an integer to days months years i have a number of days resulted from sum of datediff to many rows as integer i want to convert this days into days months years like this pr start end days_diff ------------------------------------------------------- 237 2010-06-01 2010-11-30 182 237 2010-12-01 2011-05-31 181 237 2011-06-01 2012-05-31 365 237 2012-06-01 2013-05-31 364 237 2013-06-01 2014-05-31 364 this total a 1456 days i want to convert this days into 4 years 0 months 1 days when i use the regular sum for each record into days months years it creates 3 years 12 months 1 days or any way that produce the same result even not by calculate the sum of the days difference but produce the same result 4 years 0 months 1 days not 3 years 12 months 1 days thanks for help Lost & Forgotten

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #2

      I didn't got, how you compute the years, months and days?

      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      A 1 Reply Last reply
      0
      • A ahmad_yossef

        how to convert an integer to days months years i have a number of days resulted from sum of datediff to many rows as integer i want to convert this days into days months years like this pr start end days_diff ------------------------------------------------------- 237 2010-06-01 2010-11-30 182 237 2010-12-01 2011-05-31 181 237 2011-06-01 2012-05-31 365 237 2012-06-01 2013-05-31 364 237 2013-06-01 2014-05-31 364 this total a 1456 days i want to convert this days into 4 years 0 months 1 days when i use the regular sum for each record into days months years it creates 3 years 12 months 1 days or any way that produce the same result even not by calculate the sum of the days difference but produce the same result 4 years 0 months 1 days not 3 years 12 months 1 days thanks for help Lost & Forgotten

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        How do you do the calculation? If the number of months comes out at 12 then that is 1 year.

        A 1 Reply Last reply
        0
        • A ahmad_yossef

          how to convert an integer to days months years i have a number of days resulted from sum of datediff to many rows as integer i want to convert this days into days months years like this pr start end days_diff ------------------------------------------------------- 237 2010-06-01 2010-11-30 182 237 2010-12-01 2011-05-31 181 237 2011-06-01 2012-05-31 365 237 2012-06-01 2013-05-31 364 237 2013-06-01 2014-05-31 364 this total a 1456 days i want to convert this days into 4 years 0 months 1 days when i use the regular sum for each record into days months years it creates 3 years 12 months 1 days or any way that produce the same result even not by calculate the sum of the days difference but produce the same result 4 years 0 months 1 days not 3 years 12 months 1 days thanks for help Lost & Forgotten

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          You'll need to pick a starting date, since different months have a different number of days. For example, 30 days from 1st March would be 30 days; from 1st April, it would be one month; from 1st February 2014, it would be one month and two days; from 1st February 2012, it would be one month and one day.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          1 Reply Last reply
          0
          • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

            I didn't got, how you compute the years, months and days?

            I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

            A Offline
            A Offline
            ahmad_yossef
            wrote on last edited by
            #5

            start end ------------------------------------------------------- 2010-06-01 2010-11-30 2010-12-01 2011-05-31 2011-06-01 2012-05-31 2012-06-01 2013-05-31 2013-06-01 2014-05-31 suppose this an experience periods i want to get total of this experience thanks for help Lost & Forgotten

            Kornfeld Eliyahu PeterK 1 Reply Last reply
            0
            • L Lost User

              How do you do the calculation? If the number of months comes out at 12 then that is 1 year.

              A Offline
              A Offline
              ahmad_yossef
              wrote on last edited by
              #6

              start end ------------------------------------------------------- 2010-06-01 2010-11-30 2010-12-01 2011-05-31 2011-06-01 2012-05-31 2012-06-01 2013-05-31 2013-06-01 2014-05-31 suppose this an experience periods i want to get total of this experience thanks for help Lost & Forgotten

              L 1 Reply Last reply
              0
              • A ahmad_yossef

                start end ------------------------------------------------------- 2010-06-01 2010-11-30 2010-12-01 2011-05-31 2011-06-01 2012-05-31 2012-06-01 2013-05-31 2013-06-01 2014-05-31 suppose this an experience periods i want to get total of this experience thanks for help Lost & Forgotten

                Kornfeld Eliyahu PeterK Offline
                Kornfeld Eliyahu PeterK Offline
                Kornfeld Eliyahu Peter
                wrote on last edited by
                #7

                OK... Get minimum of start (select min(start) from ... where ...) Get maximum of end (select max(end) from ... where ...) Do datediff between the two...

                I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

                A 1 Reply Last reply
                0
                • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

                  OK... Get minimum of start (select min(start) from ... where ...) Get maximum of end (select max(end) from ... where ...) Do datediff between the two...

                  I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                  A Offline
                  A Offline
                  ahmad_yossef
                  wrote on last edited by
                  #8

                  thats right in case the periods are connected some cases the periods not connected like start end ----------------------------- 2010-06-01 2010-11-30 2011-06-01 2012-05-31 2013-06-01 2014-05-31 Lost & Forgotten

                  Kornfeld Eliyahu PeterK 1 Reply Last reply
                  0
                  • A ahmad_yossef

                    start end ------------------------------------------------------- 2010-06-01 2010-11-30 2010-12-01 2011-05-31 2011-06-01 2012-05-31 2012-06-01 2013-05-31 2013-06-01 2014-05-31 suppose this an experience periods i want to get total of this experience thanks for help Lost & Forgotten

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Assuming you are storing the values as DateTime types, then you can just use a simple subtraction to get a difference value, which can be converted to years, months and days.

                    1 Reply Last reply
                    0
                    • A ahmad_yossef

                      thats right in case the periods are connected some cases the periods not connected like start end ----------------------------- 2010-06-01 2010-11-30 2011-06-01 2012-05-31 2013-06-01 2014-05-31 Lost & Forgotten

                      Kornfeld Eliyahu PeterK Offline
                      Kornfeld Eliyahu PeterK Offline
                      Kornfeld Eliyahu Peter
                      wrote on last edited by
                      #10

                      I see... In that case you can do something like this select sum(datediff(d, start,end)) from ... where ...

                      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups