468,505 Members | 1,938 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

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 2649
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
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
"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
* "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.

Similar topics

5 posts views Thread by ????? | last post: by
3 posts views Thread by Tim Chase | last post: by
2 posts views Thread by srusskinyon | last post: by
realin
4 posts views Thread by realin | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.