Results 1 to 4 of 4

Thread: Calculate months between two dates [RESOLVED]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    86

    Question Calculate months between two dates [RESOLVED]

    I have two dates say 01/01/2002 and 01/08/2003. I want to write all the months between these two dates to a spreadsheet.

    e.g

    Jan 2002
    Feb 2002
    Mar 2002
    Apr 2002
    May 2002
    etc
    etc
    etc
    Jul 2003
    Aug 2003

    How would I go about separating all the months out?
    Last edited by IrelandsOwn; Aug 15th, 2003 at 02:49 AM.

  2. #2
    Addicted Member big_k105's Avatar
    Join Date
    May 2003
    Location
    North Dakota
    Posts
    195
    one thing i would do would be to put all the months in an array first month (jan) in the first part of the array and so on.

  3. #3
    Addicted Member
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    245

    Lightbulb May I Comment?

    May be this helps...
    I have tried myself and it works fine
    VB Code:
    1. Dim Date1 As String
    2. Dim Date2 As String
    3. Dim sDate As String
    4. Dim i As Integer
    5. Dim IntDiff As Integer
    6. Dim Months  'Test to display in MsgBox
    7. Dim DateArray() As String
    8. Date1 = "01/1/2002"
    9. Date2 = "01/8/2003"
    10.  
    11. IntDiff = DateDiff("m", Date1, Date2)  'Count the Month Diff
    12. sDate = DateSerial(Year(Date1), Month(Date1) + IntDiff, Day(Date1))
    13. ReDim DateArray(IntDiff) As String   'Redim The DateArray()
    14. For i = 0 To IntDiff
    15. sDate = DateAdd("m", i, Date1)
    16. DateArray(i) = Format$(sDate, "MMM YYYY") 'THIS IS THE ARRAY THAT CAN BE USE TO DISPLAY THE DATE
    17. Months = Months & Format$(sDate, "MMM YYYY") & vbCr
    18. Next i
    19.  
    20. MsgBox Months
    I may have interpret your post wrongly
    Correct me if I made a mistake...
    Hope This Helps.. .....Enjoy Coding.....//


    zak2zak

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    86
    Nice one Zak. Exactly what I needed.

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