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. How can get total months ?

How can get total months ?

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 3 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.
  • L Offline
    L Offline
    Le rner
    wrote on last edited by
    #1

    Hi all, i have two COleDateTime type variable, i want to calculate between them in terms of months. i mean i want to calculate total months between them. i m checking COleDateTimeSpan but there is no function for GetTotalMonths please tell me how can i do this. thanks in advance.

    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

    N S 2 Replies Last reply
    0
    • L Le rner

      Hi all, i have two COleDateTime type variable, i want to calculate between them in terms of months. i mean i want to calculate total months between them. i m checking COleDateTimeSpan but there is no function for GetTotalMonths please tell me how can i do this. thanks in advance.

      IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

      N Offline
      N Offline
      nbugalia
      wrote on last edited by
      #2

      You can use GetDays () function of COleDateTimeSpan class. If you divide Days by 30, you will get the approximate months. The other option is to use int GetMonth() function of COleDateTime variables. This will return the month value in int. If you subtract the values, you can get the approximate month difference. (But you have to take care of the year also).

      L 1 Reply Last reply
      0
      • N nbugalia

        You can use GetDays () function of COleDateTimeSpan class. If you divide Days by 30, you will get the approximate months. The other option is to use int GetMonth() function of COleDateTime variables. This will return the month value in int. If you subtract the values, you can get the approximate month difference. (But you have to take care of the year also).

        L Offline
        L Offline
        Le rner
        wrote on last edited by
        #3

        Thanks.

        IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

        1 Reply Last reply
        0
        • L Le rner

          Hi all, i have two COleDateTime type variable, i want to calculate between them in terms of months. i mean i want to calculate total months between them. i m checking COleDateTimeSpan but there is no function for GetTotalMonths please tell me how can i do this. thanks in advance.

          IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          COleDateTime has GetMonth, GetDay and GetYear methods that would allow you to determine the difference in real, calendar months: int GetMonthsBetween(COleDateTime a, COleDateTime b) { if (a < b) return GetMonthsBetween(b, a); const int aMonths = a.GetYear()*12 + a.GetMonth(); const int bMonths = b.GetYear()*12 + b.GetMonth(); const bool needToRoundDown = (aMonths>bMonths) && (a.GetDay() < b.GetDay()); return (aMonths - bMonths) - ( needToRoundDown? 1 : 0 ); } This will round the month count down if necessary. For example, consider if a = June 12th and b = May 25th - you can see there's less than one full month between them.

          L 1 Reply Last reply
          0
          • S Stuart Dootson

            COleDateTime has GetMonth, GetDay and GetYear methods that would allow you to determine the difference in real, calendar months: int GetMonthsBetween(COleDateTime a, COleDateTime b) { if (a < b) return GetMonthsBetween(b, a); const int aMonths = a.GetYear()*12 + a.GetMonth(); const int bMonths = b.GetYear()*12 + b.GetMonth(); const bool needToRoundDown = (aMonths>bMonths) && (a.GetDay() < b.GetDay()); return (aMonths - bMonths) - ( needToRoundDown? 1 : 0 ); } This will round the month count down if necessary. For example, consider if a = June 12th and b = May 25th - you can see there's less than one full month between them.

            L Offline
            L Offline
            Le rner
            wrote on last edited by
            #5

            thanks

            IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

            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