1

How can I compute date to hours? For example I want to compute how many hours past during July 23 to the current date(July 25 in our country).

Outputting it like this:

Total Hours past: 48 Hours
NatsuDragneel
  • 297
  • 1
  • 4
  • 21

2 Answers2

0

I suspect there is more lurking below the surface like how you get the dates into your code. If one date originates from another country, you will have to take that into consideration. Hard to be clearer without code.

Dim thisDate As DateTime = #2/10/2010#
Dim thatDate As DateTime = #10/21/2013#

Dim ts1 As TimeSpan = thatDate.Subtract(thisDate)
' or:
' Dim ts1 As TimeSpan = thatDate - thisDate
Console.WriteLine("{0} Days or {1} hours have passed", 
        ts1.TotalDays, ts1.TotalHours)

Output:

1349 Days or 32376 hours have passed
Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
0
Private Sub days_calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Dim d1 As Date = "24/07/2014" ' From date
    Dim d2 As Date = "24/08/2014" ' To date
    MsgBox("Date difference in days : " & (d2 - d1).TotalDays & "Days")
    MsgBox("Date difference in hours : " & (d2 - d1).TotalHours & "Hours")
    MsgBox("Date difference in minutes : " & (d2 - d1).TotalMinutes & "Minutes")
End Sub
Suji
  • 1,326
  • 1
  • 12
  • 27