423,311 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,311 IT Pros & Developers. It's quick & easy.

Number of hours in date range

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
Cor
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

P: n/a
"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.


Calculate hours or add dates?
dim ts as timespan
ts = dtto.subtract(dtfrom)
msgbox(ts.totalhours)
Add days to a date:
d = d.adddays(5)

Add timespans:
ts3 = ts1.add(ts2)
--
Armin

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

Nov 20 '05 #4

P: n/a
* "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 discussion thread is closed

Replies have been disabled for this discussion.