Solved

addition of hours and also minutes in gridview i.e subtotal and grand total.

Posted on 2008-09-30
4
704 Views
Last Modified: 2012-05-05
hi folks, i'm in a trouble dat i want to add both hours and minutes taken i.e sub-total and grand total of that addition. i have seen many forums but they have given for only hours to be calculated. but i need both to be calculated simultaneously.
0
Comment
Question by:digmax
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22609486
You should be able to use either the Date structure, or a TimeSpan to do the necessary calculations to get hours and minutes.

Example:


Dim dt1 As New Date(2008, 1, 1, 23, 0, 0)
Dim dt2 As Date = Now
 
Dim ts As TimeSpan = dt2.Subtract(dt1)
Dim hours As Integer = ts.Hours
Dim minutes As Integer = ts.Minutes

Open in new window

0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 22610137
It's a little unclear if the asker wants total minutes taken, in which case the code above needs to be tweaked slightly

Dim totalMinutes As Integer = 60 * ts.Hours + ts.Minutes

Other than that, TheLearnedOne is bang on (as usual)
0
 
LVL 1

Author Comment

by:digmax
ID: 22612035
no actually i need to add the total time in the gridview. but the problem coming is its in hrs and mins format, so how to make the addition i.e subtotals
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 22616249
Are you saying that you have a string column that has hours and minutes, and you need to calculate a sum?

Example:

Duration      Decimal
-----------      -----------
1:30            1.5
1:34            1.566667
1:35            1.583333
1:45            1.75
======      =======
6:24            6.4

Formulas
-----------
Decimal = Hours + (Minutes / 60)
Time = INT(Decimal) & ":" & (Decimal - INT(Decimal) * 60)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question