Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8636567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:15:36+00:00 2026-06-12T10:15:36+00:00

mnth = DateDiff(DateInterval.Month, 8/30/2012, 10/1/2012) gives mnth = 2 . But when we look,

  • 0
mnth = DateDiff(DateInterval.Month, 8/30/2012, 10/1/2012)  

gives mnth = 2. But when we look, there is only 32 days between these dates. I am expecting a result mnth=1 as there is only 32 days between these days.

Pls help..

In my scenario i can consider a 15+ days to be a month but if it is less than 15, it should’nt be considered.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:15:37+00:00Added an answer on June 12, 2026 at 10:15 am

    To get the number of complete months you can do different things depending on your interpretation,

    Public Function CompleteMonthsBetweenA( _
            ByVal start As DateTime, _
            ByVal end As DateTime) As Integer
    
        Dim invertor = 1
    
        If (start > end) Then
           Dim tmp = end
           end = start
           start = tmp
           invertor = -1
        End If
    
        Dim diff = ((end.Year - start.Year) * 12) + end.Month - start.Month
    
        If start.Day > end.Day Then
            Return (diff - 1) * invertor
        Else
            Return diff * invertor
        End If
    End Function
    

    With this function the number of complete months between 31/05/2011 (dd/mm/yy) and 30/06/2011 is 0 but between 30/06/2011 and 31/07/2011 is 1. Which may or may not be what you expect.


    Public Function CompleteMonthsBetweenB( _
            ByVal start As DateTime, _
            ByVal end As DateTime) As Integer
    
        Dim invertor = 1
    
        If (start > end) Then
           Dim tmp = end
           end = start
           start = tmp
           invertor = -1
        End If
    
        Dim diff = ((end.Year - start.Year) * 12) + end.Month - start.Month
    
        Dim startDaysInMonth = DateTime.DaysInMonth(start.Year, start.Month)
        Dim endDaysInMonth = DateTime.DaysInMonth(end.Year, end.Month)
    
        If (start.Day / startDaysInMonth) > (end.Day / endDaysInMonth) Then
            Return (diff - 1) * invertor
        Else
            Return diff * invertor
        End If
    End Function
    

    With this function the ratio Day / DaysInMonth is taken so the relative completion of the two months can be assessed.


    Public Function CompleteMonthsBetweenC( _
         ByVal start As DateTime, _
         ByVal enddate As DateTime) As Integer
    
        Dim invertor = 1
    
        If (start > enddate) Then
            Dim tmp = enddate
            enddate = start
            start = tmp
            invertor = -1
        End If
    
        Dim diff = ((enddate.Year - start.Year) * 12) + enddate.Month - start.Month
    
        Dim remainingDays = _
          (DateTime.DaysInMonth(start.Year, start.Month) - start.Day) + enddate.Day
    
        If remainingDays < 15 Then
            Return (diff - 1) * invertor
        Else
            Return diff * invertor
        End If
    End Function
    

    This function only rounds down if the surplus days are less than the magic number 15, which I think is what you are asking for in your update.


    Public Function CompleteMonthsBetweenD( _
            ByVal start As DateTime, _
            ByVal end As DateTime) As Integer
    
        Return end.Subtract(start).TotalDays \ 30.436875
    End Function
    

    This function takes the simpler approach of dividing the total number of days by the average number of days per month in the Gregorian Calendar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that contains only Month and Year field both as int.
Goal: Rolling/Running total for all statements at the end of each month. Code: select
This is the content on my view page and i want to replace the
I am trying to translate this into Linq and cannot figure it out: SELECT
I have a ruby script repeatedly executing the following the INSERT statement using the
I am using below query to count a particular column data based on single
I inherited a new system and I am trying to make some improvements on
Here's my data: +----------+---------------+------------+---------------------+ | doctor | received_date | patient_id | accession_daily_key | +----------+---------------+------------+---------------------+
I have an SQL query like SELECT GNTD_SCHEDULE_CODE SCHEDULE, GNTD_PARENT_ACCT PARENT_ACCOUNT, GNTD_ACCOUNT_CODE ACCOUNT, GNTD_COMP_CODE,
I hope this isn't a terribly obtuse question. I notice that MySQL will let

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.