Results 1 to 31 of 31

Thread: [RESOLVED] Some doubts about DateDifference - calculating time

Threaded View

  1. #20
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Some doubts about DateDifference - calculating time

    Akhil

    When you say...
    result on clicking the button after 5 seconds is 12:00:05 AM
    ... are you referring to Me.Caption, as in

    Code:
    Private Sub Command1_Click()
        Me.Caption = DateAdd("s", DateDiff("s", Start_Time, Now), "0:0:0")  
    End Sub
    If so, perhaps you could, for troubleshooting purposes, break apart
    that line of code, as in:

    Code:
    Private Sub Command1_Click()
        v1 = DateDiff("s", Start_Time, Now)
        v2 = DateAdd("s", v1, "0:0:0")  
        v3 = Now
        v4 = DateAdd("s", v1, v3) 
    End Sub
    If I understand what is happening, you'd get these results:
    1. v1 = 5 .... calculates the difference
    2. v2 = 12:00:05 AM .... adds said difference to a preset time, namely, "0:0:0"
    3. v3 = 5/21/2010 9:22:41 AM
    4. v4 = 5/21/2010 9:22:46 AM


    Comments:
    1. No issue here
    2. The "problem" here is you are doing trying to add 5 seconds to "0:0:0"
      (which is being interpreted as 12:00:00 AM). This seems to be the
      where the breakdown in your logic flow is occurring.
    3. Hypothetical value of NOW
    4. No DateAdd problem here, because you are adding 5 seconds to a time
      (which also contains the date).


    Does that help?

    Spoo
    Last edited by Spoo; May 21st, 2010 at 08:42 AM.

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