Results 1 to 3 of 3

Thread: [02/03] Skipping Dates

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    Question [02/03] Skipping Dates

    Hello everyone.

    I need to determine if a dynamic date is in a specified date range.

    For example, I have 1 initial start date, then during the cours of the application, I add x amount of weeks / x amount of months to it, until it reaches the specified end date. - This all works fine.

    What I have to do now, is to compensate for a 3 week leave period ( the last 2 weeks of dec and the first week of jan ). because of the 3 week break period, I need to add the "extra" 3 weeks to the current dynamic date in that range.

    Can anyone please give me an idea, perhaps example on how I should go about doing this?


    I'm alread using DateAdd to add the weeks / months. What I'm battling with is to determine the 3 weeks leave period.

    For example, say I have been adding the dates and everything goes well.
    Let us also realise that the 3 week break period starts the 15th december ( which may differ depending on input).

    So now, after I have added the date, and I see that this date is between 15 december and 5 january, I have to add an additional 3 weeks to it,

    how would I do this?

    Thank you.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [02/03] Skipping Dates

    Don't use DataAdd in VB.NET.
    vb.net Code:
    1. Dim myDate As Date = Date.Today
    2.  
    3. 'Add a week.
    4. myDate = myDate.AddDays(7)
    5.  
    6. 'Add a month.
    7. myDate = myDate.AddMonths(1)
    8.  
    9. If (myDate.Month = 12 AndAlso myDate.Day >= 15) OrElse _
    10.    (myDate.Month = 1 AndAlso myDate.Day <= 5) Then
    11.     myDate = myDate.AddDays(21)
    12. End If
    You could use Date literals at the end there but the way I've done it will work for any year. You can also use variables for the days of December and January if they will vary.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    Re: [02/03] Skipping Dates

    Thank you sir, I'll give that a try

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