Results 1 to 4 of 4

Thread: [RESOLVED]Date Ranges Problem........

  1. #1

    Thread Starter
    Hyperactive Member ashay's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai,India
    Posts
    278

    Smile [RESOLVED]Date Ranges Problem........

    hi,

    I need to find the dates between a range of dates......

    eg:
    the dates are in dd/mm/yyyy format

    the user specifies 2 dates

    Date1:15/4/2003
    Date2:20/4/2003

    I want to retrieve the dates between Date1 and Date2.i.e.
    15/4/2003,16/4/2003,17/4/2003,18/4/2003,19/4/2003,20/4/2003

    It is easy to retrive the dates of the same month...but probs arise when date1 and date2 are of different months.....n more probs for diff years......

    any suggestions or examples highly appreciated......

    regds,
    ashay
    Last edited by ashay; Apr 15th, 2003 at 09:31 AM.
    "If you should die before me, ask if you could bring a friend."
    - Stone Temple Pilots

  2. #2
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456

    Re: Date Ranges Problem........

    Originally posted by ashay
    hi,

    I need to find the dates between a range of dates......

    eg:
    the dates are in dd/mm/yyyy format

    the user specifies 2 dates

    Date1:15/4/2003
    Date2:20/4/2003

    I want to retrieve the dates between Date1 and Date2.i.e.
    15/4/2003,16/4/2003,17/4/2003,18/4/2003,19/4/2003,20/4/2003

    It is easy to retrive the dates of the same month...but probs arise when date1 and date2 are of different months.....n more probs for diff years......

    any suggestions or examples highly appreciated......

    regds,
    ashay
    Create a new form and add a listbox to it...

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim l_dtStartDate As Date
    5. Dim l_dtEndDate As Date
    6.  
    7.     l_dtStartDate = Now
    8.     l_dtEndDate = DateAdd("yyyy", 1, l_dtStartDate)
    9.    
    10.     MsgBox l_dtStartDate
    11.     MsgBox l_dtEndDate
    12.    
    13. Dim i As Long
    14. Dim l_dtTempDate
    15.  
    16.     While l_dtStartDate <= l_dtEndDate
    17.         List1.AddItem l_dtStartDate
    18.         l_dtStartDate = DateAdd("d", 1, l_dtStartDate)
    19.     Wend
    20. End Sub

    This will fill all the dates in the listbox between today and year from today. You can change the Start and End date for different results.

  3. #3
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611
    Try this
    VB Code:
    1. private sub DateReturn (Date1 as date, Date2 as date)
    2. dim Counter as integer
    3. if Date1 < Date2 then
    4.     msgbox "Error Date1 lies before date2!!"
    5.     exit sub
    6. end if
    7. counter = 1
    8. while notl Date1 = Date2
    9.     Date1 = dateadd("d",1,date1)
    10.     msgbox Date1
    11. wend

    This should work, haven't tested it. But the idea should be clear

  4. #4

    Thread Starter
    Hyperactive Member ashay's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai,India
    Posts
    278
    hi techyspecy n Lightning,

    thanxxxxxxxxxxxxxxxxxxxxxxxxx a lot........

    regds,
    ashay
    "If you should die before me, ask if you could bring a friend."
    - Stone Temple Pilots

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