Hi again, i am working for a new project [payroll system] , i want to know how can i calculate late like for example my working time should be 8:00am-5:00pm and one day i go to office at 8:30 am , can someone tell me how can i save in database the late in format like this 00:30 ? i really need help

@ddanbe, i tried this code ,but i got error in ("{0} - {1} = {2}", workingtime, timeIn, late) , the comma after {2}" is error

  Dim workingtime As DateTime = Txtworkingtme.Text
        Dim timeIn As DateTime = Txttimein.Text
        Dim late As TimeSpan = workingtime - timeIn
       Txtlate .Text = ("{0} - {1} = {2}", workingtime, timeIn, late)

Use a constructor like this: Dim startTime As New TimeSpan( 8, 0, 0 )
And also one for the late time.

'Somehow to record somewhere:
Dim hours as integer = 8
Dim minutes as integer = 30
Dim seconds as integer = 0
Dim lateTime As New TimeSpan( hours, minutes, seconds )

Now use the substract method to get the desired result.

@ddanbe, i got it now, but it only works because i declare the value, what if i have late of 45minutes or higher, how can i subtract it without declaring the value like the above?

Timer1_Tick
lbltime.Text = Format(Now, "h:mm:ss")

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim startTime As New TimeSpan(8, 0, 0)
        Dim lateTime As New TimeSpan(lbltime.Text)
        Txtlate.Text = (lateTime - startTime).ToString
    End Sub

i got error at Dim lateTime As New TimeSpan(lbltime.text)
Conversion from string "1:16:02" to type 'Long' is not valid.

lbltime.Text is a sting type The TimeSpan constructor expects three integers. You have to somehow decompose your textbox string into 3 integers or use the Parse method.

    Dim values As String = lbltime.Text
        For Each value As String In values
            Try
                Dim interval As TimeSpan = TimeSpan.Parse(value)
                Dim startTime As New TimeSpan(8, 0, 0)
                Dim lateTime As New TimeSpan(values)
                Txtlate.Text = (lateTime - startTime).ToString
            Catch ex As Exception
            End Try

        Next

i try this code but i got nothing. honestly i dont understand about parsing , so its kinda hard to understand the link that you gave to me.

i also try this

       Dim values As String = lbltime.Text
        For Each value As String In values
            Try
                Dim interval As TimeSpan = TimeSpan.Parse(value)
                Dim startTime As New TimeSpan(8, 0, 0)
                Txtlate.Text = (interval - startTime).ToString
            Catch ex As Exception

            End Try


        Next

its working but, the total of (interval - startTime) is not right

This snippet should give you an idea of how to work the difference out:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim str As String = ""
        Dim format As String = "HH,mm"
        Dim diff As TimeSpan
        Dim constSt As TimeSpan = New TimeSpan(0, 8, 0, 0, 0) 'Constant start Time
        Debug.Print(constSt.ToString)
        Dim start As TimeSpan = TimeSpan.Parse(Now.ToShortTimeString) 'actual start time
        diff = start - constSt 'difference in hours,minutes,seconds
        Debug.Print(diff.ToString)
    End Sub

On line 1 you are defining values as a string. Then you iterate over a string ? You can only iterate over an array of strings.

From my opinion, MaskedTextBox control should give you more flexibility to input the time values like start time and end time.

Take two MaskedTextBox controls, one for start time and second one for present/end time. In property window change two properties of each MaskedTextBox control.

Changable Property Values
1) Set MaskedTextBox's PromptChar property to "0"
2) Set MaskedTextBox's Mask Property to "00:00:00"

The codes to check the difference of these two times are as follows

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim stTime() As String
        Dim endTime() As String

        stTime = Split(MaskedTextBox1.Text, ":")
        endTime = Split(MaskedTextBox2.Text, ":")


        Dim startTime As TimeSpan = New TimeSpan(Val(stTime(0)), Val(stTime(1)), Val(stTime(2)))
        Dim PresentTime As TimeSpan = New TimeSpan(Val(endTime(0)), Val(endTime(1)), Val(endTime(2)))

        Dim difTime As TimeSpan = PresentTime - startTime

        MessageBox.Show(String.Format("You are already {0}hour(s) {1}minute(s) {2}second(s) late.", difTime.Hours, difTime.Minutes, difTime.Seconds))

    End Sub

You can try it. Hope it can solve your probles.

Thank you guys for helping, it really help me. :D

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.