Results 1 to 5 of 5

Thread: [RESOLVED] Adding to a date?

  1. #1

    Thread Starter
    Hyperactive Member Teseng's Avatar
    Join Date
    Sep 2007
    Location
    Tupelo, MS
    Posts
    281

    Resolved [RESOLVED] Adding to a date?

    I'm trying to create a timescale, and need to add 5 minutes to a date every 10 seconds, i have a timer setup on the right interval, but i can't figure out how to add 10 minutes to a DATE variable.

    Doing MyTime = MyTime + 10 just adds 10 days, i tried using 0.1 and it went wacko and displayed a seemingly random time. Any help?

  2. #2
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Re: Adding to a date?

    VB has a built in function called DateAdd for this kind of thing,

    make a new project and paste this into an event of your choice:

    Code:
    Dim aDate As Date
    aDate = Now()
    MsgBox aDate
    MsgBox DateAdd("n", 5, aDate) 'Adds 5 minutes to the aDate variable
    Heres a list of the possible values for Interval that i copied from msdn

    String Unit of time interval to add
    d Day; truncated to integral value
    y Day; truncated to integral value
    h Hour; truncated to integral value
    n Minute; truncated to integral value
    m Month; truncated to integral value
    q Quarter; truncated to integral value
    s Second; truncated to integral value
    w Day; truncated to integral value
    ww Week; truncated to integral value
    yyyy Year; truncated to integral value
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

  3. #3

    Thread Starter
    Hyperactive Member Teseng's Avatar
    Join Date
    Sep 2007
    Location
    Tupelo, MS
    Posts
    281

    Re: Adding to a date?

    Perfect, thanks much Arachnid.

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: [RESOLVED] Adding to a date?

    Quote Originally Posted by Teseng
    I'm trying to create a timescale, and need to add 5 minutes to a date every 10 seconds, i have a timer setup on the right interval, but i can't figure out how to add 10 minutes to a DATE variable.

    Doing MyTime = MyTime + 10 just adds 10 days, i tried using 0.1 and it went wacko and displayed a seemingly random time. Any help?
    0.1 is interpreted as 10% of a day which is not 10 minutes. You're probably thinking of second.millisecond precision wherein 0.1 or 10% of a second correctly converts to 100 milliseconds.

  5. #5
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Re: Adding to a date?

    Quote Originally Posted by Teseng
    Perfect, thanks much Arachnid.
    No problem
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

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