CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 1999
    Location
    WA
    Posts
    65

    Calculating Months using a COleDateTimeSpan object

    Hello, I need to calculate Months using a COleDateTimeSpan object. With this object you can get days, hours, minutes, and seconds. I need to calculate Months. I have already added code that will calculate years, and weeks (which are both easy, just nDays * 365 (years) or nDays * 7 (weeks) but Months are more difficult).

    Can anyone help me with a calculation? I was thinking about this, and tried it, but it didn't work properly:


    double dYears = nTotalDays / 365.25;
    int nMonths = (int)nYears * 12;




    Thanks for any help that you can offer!

    - Troy

  2. #2
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: Calculating Months using a COleDateTimeSpan object

    you can't do it like that, since months have different lengths
    BTW, so do years

    Sally


  3. #3
    Join Date
    May 1999
    Location
    WA
    Posts
    65

    Re: Calculating Months using a COleDateTimeSpan object

    Yes, I realize that this piece of code doesn't work, but what I need is an algorithm that will work.

    Do you have any suggestions?

    - Troy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured