I have a time values in MS Access database

4:30
2:15
3:20
4:45

I want to sum the time using VB code .The sum of the time should be 14:50 hrs not 14:10 hrs. Please help

Hi, i think adding two time values are possible in VB6 just using time1 + time2.

Ex

Dim Time1 As Date
   Dim Time2 As Date
   Dim TotalTime As Date
   
   Time1 = "2:15"
   Time2 = "4:30"
   
   TotalTime = Time1 + Time2
   Time1 = "3:20"
   Time2 = "4:45"
   TotalTime = TotalTime + Time1 + Time2
   MsgBox Hour(TotalTime) & " Hours " & Minute(TotalTime) & " Minutes" & Second(TotalTime) & " Seconds"

Hi,

You want to get Total in a Single Query..?
Is the Field in Access Table DateTime field or Single/Decimal field..?
You can do it in a single query...

Regards
Veena

Hi,

You want to get Total in a Single Query..?
Is the Field in Access Table DateTime field or Single/Decimal field..?
You can do it in a single query...

Regards
Veena

It is MS Access Date/time field. I tried using sum function but I did not get correct result.

Hi,

Instead of simply using Sum, use this Query:

Select Sum(Val(MyDateTimeFld)) From MyTable

You will get total Time,
Later you need to get the Decimal Part, Integer Divide by 60, add it to Hours part, and keep the remainder in Decimal for Minutes..

Regards
Veena

Sorry I am a beginner in VB so pls give me the full details of code. here I give my database details

database name - DKavitha.mdb
Table name - TKursus
fields are
Course no, date ,time and total time.
now I want to know how to get the totoal hours
I use data control and Data Bound Grid control.
pls help me give full code with details
Thank you

Sorry I am a beginner in VB so pls give me the full details of code. here I give my database details

database name - DKavitha.mdb
Table name - TKursus
fields are
Course no, date ,time and total time.
now I want to know how to get the totoal hours
I use data control and Data Bound Grid control.
pls help me give full code with details
Thank you

use SQL Statement:
like this,
'if you use adodc for connection,try this;
-Adodc1.Recordset = Select Sum(time) From TKursus
-Adodc1.Refresh
note: this SQL statement is use to add the number in one field,,

@sbchandru

You need to post your working code before asking for code and specify in which part you are facing problem.

Here we do not run a free code writing service.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.