473,231 Members | 1,643 Online

Number of hours in date range

Hi,
Is ther a simple way to calculate number of hours in a date range. (dtFrom
as date , dtTo as date)
Had a look at timespan, but can's see that it's possible to add dates.

Tnx
Totto
Nov 20 '05 #1
4 2816
Hi,

Dim ts As New TimeSpan

ts = Now.Subtract(DateTime.Parse("2/2/2004"))

Me.Text = (ts.Days * 24 + ts.Hours).ToString

Ken

------------------------------

"Totto" <ta*********@norcon.no> wrote in message
news:OS**************@TK2MSFTNGP11.phx.gbl...
Hi,
Is ther a simple way to calculate number of hours in a date range. (dtFrom
as date , dtTo as date)
Had a look at timespan, but can's see that it's possible to add dates.

Tnx
Totto

Nov 20 '05 #2
Hi Totto,

Look at timespan to the methods totalhours, add and subtract. It goes a
little bit on a totally different way than we are used to.

I hope this helps?

Cor
Nov 20 '05 #3
"Totto" <ta*********@norcon.no> schrieb
Hi,
Is ther a simple way to calculate number of hours in a date range.
(dtFrom as date , dtTo as date)
Had a look at timespan, but can's see that it's possible to add
dates.

dim ts as timespan
ts = dtto.subtract(dtfrom)
msgbox(ts.totalhours)

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
* "Totto" <ta*********@norcon.no> scripsit:
Is ther a simple way to calculate number of hours in a date range. (dtFrom
as date , dtTo as date)
Had a look at timespan, but can's see that it's possible to add dates.

\\\
Dim ts As TimeSpan = d1.Subtract(d2)
MsgBox(ts.TotalHours.ToString())
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.