+ Reply to Thread
Results 1 to 4 of 4

Find time difference

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Find time difference

    Hi folks

    I want to find the time difference using vba. when the form is intialized then the starttime gets stored in textbox1 as follows:

    textbox1.value=format(now,"hh:mm:ss")

    The finish time is calculated when the enter button is clicked and is stored in variable t as follows:
    dim t as date
    t=format(now,"hh:mm:ss")
    Now I am writing the following line of code to find time diff but it gives me type mismatch error:

    dim b as date
    b=t-textbox1.value

    Can anyone please figure it out.

    Thanks
    Aman

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Find time difference

    Try to put this code at form initialization:
    textbox1.value = Now - Date
    then use this code at enter button click:
    dim t as Double
    t = Now - Date
    and then to calculate difference you can use:
    Dim b as Double, c as string
    b = t - Textbox1.value
    c = format (b, "hh:mm:ss")
    Regards,
    Antonio

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Find time difference

    Look at datediff (VBEditor, F1)

  4. #4
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Find time difference

    Thanks a lot Antonio. It works absolutely fine.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1