Solved

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

Posted on 2008-09-30
4
709 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

732 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