DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: diference between two hours and dates

  1. #1
    Join Date
    Sep 2005
    Posts
    10

    diference between two hours and dates

    hi,
    i need a function to show a diference between two hours and dates example:
    start: 10:00am end 3:00am result = 17:00

    start:10-2-2007 end: 12-2-2007 = 2 days

    in php i have a function for this, there is in vb samething that can do the same? or someone
    know a function do that?
    thanks for your help
    bruno

  2. #2
    Join Date
    Mar 2005
    Location
    Los Angeles, Calif. AKA: Gangsta Yoda™
    Posts
    455
    Use DateDiff function to calculate the differences in dates and times.

    "17:00"

    Code:
    Format(DateDiff("h", #10/2/2007 10:00:00 AM#, #10/3/2007 3:30:00 AM#), "##") & ":00"
    "2 Days"
    Code:
    Format(DateDiff("d", #2/10/2007#, #2/12/2007#) + 1, "d") & " Days"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer code questions via PMs.
    Microsoft MVP 2006-2009
    Office Development FAQ (VBA, VB6, VB.NET, C#)
    Software Engineer MCP (VB6 & .NET)
    Reps & Rating PostsVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6Outlook Global Address List

  3. #3
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    Make your own like this:
    Code:
    Public Function TimeDiff(DateTimeStart As Date, DateTimeEnd As Date)
      Dim h As Long
      Dim m As Long
      Dim s As Long
      
      'get difference in seconds
      s = DateDiff("s", DateTimeStart, DateTimeEnd)
      h = s \ 3600   'calculate hours
      s = s Mod 3600 'remove hours
      m = s \ 60     'calculate minutes
      s = s Mod 60   'remove minutes
      'conveert to Time format
      TimeDiff = h & Format(m, "\:0#") & Format(s, "\:0#;#;#")
    End Function
    
    Debug.Print TimeDiff(#10/2/2007 10:00:00 AM#, #10/3/2007 3:30:00 AM#)

Similar Threads

  1. how to change CREATED to POSTED dates
    By karen987 in forum Database
    Replies: 0
    Last Post: 04-01-2007, 08:18 AM
  2. working with dates in SQL
    By rodmc in forum Database
    Replies: 1
    Last Post: 01-18-2006, 08:47 AM
  3. Number of Calendar days between 2 dates
    By sheryl kemp in forum Database
    Replies: 2
    Last Post: 10-23-2002, 11:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center