Solved

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

Posted on 2008-09-30
4
698 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project

856 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