welcome Dear all
this my first topic in DANIweb so that I'm waiting for more than help ,
I try to design time calculator to calculate time by Minutes
you can see code
((((

Private Sub Command2_Click()
If Val(Text1.Text) = 0 Then MsgBox "type any Date and Time value": Exit Sub
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text6.Text = DateDiff("D", Text1.Text, Text3.Text)
Text5.Text = DateDiff("h", Text1.Text, Text3.Text)
Text7.Text = DateDiff("n", Text1.Text, Text3.Text)
Text8.Text = DateDiff("n", Text1.Text, Text3.Text)
End Sub

))))))))


now i want calculate time in work hours only (form 9AM till 5 Pm) and Ignore other time

for Example :
when i calculate time between this Duration
from : 11/10/2010 11:05 AM

Till : 13/10/2010 9:20 PM

program results:

3495 Minutes

--------
But This is not true I want my Results be same that :

first day = from 11:05 am till 5 pm = 355
second day= from 9:00 am till 5 pm = 480
thread day= from 9:00 am till 5 pm = 480 and Ignore time from 5PM till 9:20pm

Total Minutes = 355+480+480 = 1315 NOT 3495
This my Pro Image


[img]http://0ux1ba.bay.livefilestore.com/y1pAlelPoGm8rAei34F_3H9VmnAnJ9aJA89woQCTcLM7wwS2tvWI5xgy98ix-DhTcGpqDU_3fCmebq5MfDrwe5cJPL0Dr7nKHy8/calc.JPG?psid=1[/img]

this my E-mail
--snipped--

Recommended Answers

All 10 Replies

To convert the times before doing the sum, use the following -

Dim BrowseTime As Integer, BrowseTimeUnit As String

If BrowseTime < 60 Then
                BrowseTimeUnit = BrowseTime & " Mins"
            ElseIf BrowseTime >= 60 And BrowseTime < 1440 Then
                BrowseTime = BrowseTime / 60
                BrowseTimeUnit = BrowseTime & " Hrs"
            ElseIf BrowseTime >= 1440 Then
                BrowseTime = BrowseTime / 1440
                BrowseTimeUnit = BrowseTime & " Days"
            End If

Dear AndreRet
you are more than welcome ,and thanks for your prompt replay but i tried it without any New action

I'll post a full solution for you tomorrow.:)

5 Days Ago
still wait you

Sorry, with my company closing for holidays, Christmas etc, I'm not so active.:)

Be patient during these times, I will post as soon as I get back to spending more time here...;)

Hi,
just inset all the components on a form, name them accordingly and copy all the codes to command1 sub routing. That is all

COMPONENTS USED

DTPicker1 for date1
DTPicker2 for date2
Text1 for 1st day time
Text2 for Last day time
Text3 for total minutes worked
command button(command1)

Private Sub Command1_Click()

lth1 = Len(Text1)
lth2 = Len(Text2)
If lth1 < 7 Or lth2 < 7 Then
MsgBox "Enter the correct time format, e.g. '00:00am'"
Exit Sub
ElseIf lth1 > 7 Or lth2 > 7 Then
MsgBox "Enter the correct time format, e.g. '00:00am'"
Exit Sub
End If

Time1 = Left(Text1, 5)
Time2 = Left(Text2, 5)
Tx1 = Left(Time1, 2)
Tx2 = Left(Time2, 2)
Ty1 = Right(Time1, 2)
Ty2 = Right(Time2, 2)
Tz1 = Right(Text1, 2)
Tz2 = Right(Text2, 2)

If Int(Tx1) > 5 And UCase(Tz1) = "AM" Then
hrdiff1 = (12 - Val(Tx1)) + 5
mindiff1 = (Val(hrdiff1) * 60) - Val(Ty1)
ElseIf Int(Tx1) > 5 And UCase(Tz1) = "PM" Then
hrdiff1 = 5
mindiff1 = (Val(hrdiff1) * 60) - Val(Ty1)
ElseIf Int(Tx1) < 5 And UCase(Tz1) = "PM" Then
hrdiff1 = 5 - Val(Tx1)
mindiff1 = (Val(hrdiff1) * 60) - Val(Ty1)
Else
Exit Sub
End If

If Int(Tx2) >= 9 And UCase(Tz2) = "AM" Then
hrdiff2 = Val(Tx2) - 9
mindiff2 = (Val(hrdiff2) * 60) + Val(Ty2)
ElseIf Int(Tx2) < 12 And UCase(Tz2) = "PM" Then
hrdiff2 = Val(Tx2) + (12 - 9)
mindiff2 = (Val(hrdiff2) * 60) + Val(Ty2)
ElseIf Int(Tx2) = 12 And UCase(Tz2) = "PM" Then
hrdiff2 = 12 - 9
mindiff2 = (Val(hrdiff2) * 60) + Val(Ty2)
Else
Exit Sub
End If


diff1 = DateDiff("d", DTPicker1, DTPicker2)

k = 0
minspent = mindiff1
For i = 1 To diff1
k = k + 1
If k = diff1 Then
minspent = minspent + mindiff2
Else
minspent = minspent + 480
'''''Since from 9am to 5pm total minutes is 480 (8*60)
End If
Next

Text3 = minspent & "min"
End Sub

Hi,
Find the attachment of the detail below.

Hi,
many thanks My friend mrteey2k for your efforts and code
after i install all components as your design and run but i found some error
same that :
if you calculate that
2/11/2010 9:00am till 3/11/2010 4:50pm = 950 minutes (correct answer )
PLZ Be NOTe if we Calc again
2/11/2010 9:00am till 3/11/2010 5:50pm = 1010 minutes
why ???????

Plz be sure CODE will ignore all time after 5:00pm till next day

Many Thanks again

commented: We are NOT a coding service! Do your own homework! -3

Hi,
many thanks My friend mrteey2k for your efforts and code
after i install all components as your design and run but i found some error
same that :
if you calculate that
2/11/2010 9:00am till 3/11/2010 4:50pm = 950 minutes (correct answer )
PLZ Be NOTe if we Calc again
2/11/2010 9:00am till 3/11/2010 5:50pm = 1010 minutes
why ???????

Plz be sure CODE will ignore all time after 5:00pm till next day

Many Thanks again

Look at the code an figure it out. We are not your personal coding service. You could have spent the last 10 days thinking rather than sitting on your butt hoping someone can do your homework for you.

I'm surprised andreRet even offered code. And mrteey2k, we do not do homework for others. We help them fix their own code...

I'm surprised andreRet even offered code

Hence no more advice offered from my last post.:) The poster seems to think that he can copy and paste the guideline code and all will be fine. Does not even try to work around and find a solution himself.

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.