Results 1 to 3 of 3

Thread: SOLVED: Adding day(s) to a date : S

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Posts
    406

    Resolved SOLVED: Adding day(s) to a date : S

    I saw some posts about it and tried to duplicate, but it is not working.

    Here is my code:

    Code:
    dteDays(ii) = dtpDate1.Value
    dteDays(ii).AddDays(i)
    ii = ii + 1
    dteDays is an array of dates, starting with dtpDate1

    The value of dtpDate1 is 3/31/06

    The code above is in a For/Next loop.

    i is 0 through some number, we'll say 3 for this example.

    No matter what the value of i is, all of the dates in the array, dteDays, are equal to 3/31/06.

    what am i doing wrong?

    Thanks in advance!!!
    Last edited by Hack; Mar 31st, 2006 at 09:32 AM. Reason: Added green resolved checkmark

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

    Re: Adding day(s) to a date : S

    AddDays and the other similar methods do not change the value of the Date object they are called on. They return a new Date object with the new value. To change the existing Date object you'd have to do something like this:
    VB Code:
    1. myDate = myDate.AddDays(1)
    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
    Jul 2003
    Posts
    406

    Re: Adding day(s) to a date : S

    you beat me! i just figured that out...i did thisi nstead:

    Code:
    dteDays(ii) = dtpDate1.Value.AddDays(i)
    ii = ii + 1
    and it works perfectly...thanks!

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