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. General Programming
  3. C / C++ / MFC
  4. Calculate Date Difference in months

Calculate Date Difference in months

Scheduled Pinned Locked Moved C / C++ / MFC
question
2 Posts 2 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
    AksharRoop
    wrote on last edited by
    #1

    Hi All, I am writing one function that should return me a difference between given dates in months. I know it can easily be done by getting difference in years, months and days. Then calculate months like trmMonths = 0; trmMonths += years * 12; trmMonths += months; But i am not sure about what to do with days, because sometimes it may happen that difference between dates would be years = 1 months = 11 days = 28. in this case the difference between dates should be 24months. Can anyone give me idea on how days can be handled here to get accurate difference? Thanks, AksharRoop

    C 1 Reply Last reply
    0
    • A AksharRoop

      Hi All, I am writing one function that should return me a difference between given dates in months. I know it can easily be done by getting difference in years, months and days. Then calculate months like trmMonths = 0; trmMonths += years * 12; trmMonths += months; But i am not sure about what to do with days, because sometimes it may happen that difference between dates would be years = 1 months = 11 days = 28. in this case the difference between dates should be 24months. Can anyone give me idea on how days can be handled here to get accurate difference? Thanks, AksharRoop

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      AksharRoop wrote:

      But i am not sure about what to do with days, because sometimes it may happen that difference between dates would be years = 1 months = 11 days = 28. in this case the difference between dates should be 24months.

      :confused: Err I'm totally confused by your sentence here. Could you explain a bit better what is the problem exactly ? Are you using COleDateTime and/or COleDateTimeSpan classes ? This could help you manipulating times.

      Cédric Moonen Software developer
      Charting control [v1.5] OpenGL game tutorial in C++

      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