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. sum of datediff to many dates

sum of datediff to many dates

Scheduled Pinned Locked Moved Database
10 Posts 6 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

    i have this periods of experience i want to calculate the sum or total period of these periods 2004-01-06 2004-07-05 2004-07-07 2004-11-30 2010-07-01 2010-07-29 2011-06-12 2011-07-28 2012-07-22 2012-08-20 2013-10-17 2015-05-17 Lost & Forgotten

    T Kornfeld Eliyahu PeterK J 3 Replies Last reply
    0
    • A ahmad_yossef

      i have this periods of experience i want to calculate the sum or total period of these periods 2004-01-06 2004-07-05 2004-07-07 2004-11-30 2010-07-01 2010-07-29 2011-06-12 2011-07-28 2012-07-22 2012-08-20 2013-10-17 2015-05-17 Lost & Forgotten

      T Offline
      T Offline
      Tim Carmichael
      wrote on last edited by
      #2

      If you provide the query you are trying to get working, you are more likely to get help. What is the underlying database? SQLServer, Oracle, Postgres, etc?

      A 1 Reply Last reply
      0
      • T Tim Carmichael

        If you provide the query you are trying to get working, you are more likely to get help. What is the underlying database? SQLServer, Oracle, Postgres, etc?

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

        sql i made a query calculate the datediff in days and sumed all days now i want to convert this days (integer) to years months and days thanks Lost & Forgotten

        T 1 Reply Last reply
        0
        • A ahmad_yossef

          i have this periods of experience i want to calculate the sum or total period of these periods 2004-01-06 2004-07-05 2004-07-07 2004-11-30 2010-07-01 2010-07-29 2011-06-12 2011-07-28 2012-07-22 2012-08-20 2013-10-17 2015-05-17 Lost & Forgotten

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

          If the answer for your question isn't satisfying, than refine your question - do not post it again... http://www.codeproject.com/Forums/1725/Database.aspx?select=4775204&tid=4775204[^]

          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

            If the answer for your question isn't satisfying, than refine your question - do not post it again... http://www.codeproject.com/Forums/1725/Database.aspx?select=4775204&tid=4775204[^]

            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

            i am sorry Lost & Forgotten

            L 1 Reply Last reply
            0
            • A ahmad_yossef

              i am sorry Lost & Forgotten

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

              Click on your name and you can find all your previous messages.

              1 Reply Last reply
              0
              • A ahmad_yossef

                sql i made a query calculate the datediff in days and sumed all days now i want to convert this days (integer) to years months and days thanks Lost & Forgotten

                T Offline
                T Offline
                Tim Carmichael
                wrote on last edited by
                #7

                ahmad_yossef wrote:

                i want to convert this days (integer) to years months and days

                Well, break it down.. if you have the number of days, how many days in a year? Let's assume 365; so number of years in int(number of days / 365). Months... let's assume 30 days on average... Months = int((number of days - years * 365) / 30) And days are then number of days - years * 365 - months * 30 If that doesn't work, better define what you're after. Given the sample dates you provided, what are the values you calculated for years, months and days?

                A 1 Reply Last reply
                0
                • T Tim Carmichael

                  ahmad_yossef wrote:

                  i want to convert this days (integer) to years months and days

                  Well, break it down.. if you have the number of days, how many days in a year? Let's assume 365; so number of years in int(number of days / 365). Months... let's assume 30 days on average... Months = int((number of days - years * 365) / 30) And days are then number of days - years * 365 - months * 30 If that doesn't work, better define what you're after. Given the sample dates you provided, what are the values you calculated for years, months and days?

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

                  thanks for your replay but i face a problem when i have a number like 1456 the query will be like that SELECT dayss, dayss / 365 AS years, (dayss - dayss / 365 * 365) / 30 AS Months, (dayss - dayss / 365 * 365) - (dayss - dayss / 365 * 365) / 30 * 30 AS days FROM dbo.lv_npay_tmp3 which will return days1 years months days 1456 3 12 1 and it should be days1 years months days 1456 4 0 1 i hope you got me thanks alot Lost & Forgotten

                  Richard DeemingR 1 Reply Last reply
                  0
                  • A ahmad_yossef

                    thanks for your replay but i face a problem when i have a number like 1456 the query will be like that SELECT dayss, dayss / 365 AS years, (dayss - dayss / 365 * 365) / 30 AS Months, (dayss - dayss / 365 * 365) - (dayss - dayss / 365 * 365) / 30 * 30 AS days FROM dbo.lv_npay_tmp3 which will return days1 years months days 1456 3 12 1 and it should be days1 years months days 1456 4 0 1 i hope you got me thanks alot Lost & Forgotten

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

                    1456 == (3 × 365) + 361. That's clearly not 4 years and 1 day. The problem is that you're assuming 365 days per year, but only 30 days per month. (30 × 12) = 360, so you've lost five days. You need to assume (365 / 12) = 30.4166666... days per month, which will give you an answer of 3 years, 11 months and 27 days.

                    SELECT
                    dayss,
                    dayss / 365 As years,
                    Cast(Floor((dayss % 365) * 12 / 365.0) As int) As Months,
                    (dayss % 365) - Cast(Floor((dayss % 365) * 12 / 365.0) * 365.0 / 12 As int) As days
                    FROM
                    dbo.lv_npay_tmp3


                    "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
                    • A ahmad_yossef

                      i have this periods of experience i want to calculate the sum or total period of these periods 2004-01-06 2004-07-05 2004-07-07 2004-11-30 2010-07-01 2010-07-29 2011-06-12 2011-07-28 2012-07-22 2012-08-20 2013-10-17 2015-05-17 Lost & Forgotten

                      J Offline
                      J Offline
                      jschell
                      wrote on last edited by
                      #10

                      I will just say that this sort of exercise seldom ends well without business requirements. I am not going to analyze all possible interpretations but I will provide and example from your own data. 2013-10-17 2015-05-17 A business person asks you for how many years in that. All of the following are possible answers. - One. 2013-10 to 2014-10 is one year, but 2014-10 to 2015-05 isn't. - Zero. Because 2013-10 to 2014-10 is one year but it isn't 2014-10 yet - Three. 2013, 2014, 2015 = 3. - Two. 2013-10 to 2014-10 is one year, but 2014-10 to 2015-05 is partial, so round up to get 2. - Five. The dates are supposed to be based on the contract period not the annual service dates (which the above dates are.) - 17. Because the person that actually wants this wants a count of months covered.

                      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