C#.net

Elapsed Time Calculation using Vb.net

This Elapsed Time Calculation System is useful for check the employees working time. This system start to work when employee log in to the office until log off from office.

Import the Following Namespace

Dim date1 As String
Dim i, flg As Integer
Dim th, ot As Decimal
Public st As String
Public wh As Decimal

Create the Function

Private Function CalculateHours(ByRef tm1 As Date, ByRef tm2 As Date) As Decimal
        Dim i, j As Double

        i = Hour(tm2) - Hour(tm1)
        j = (Minute(tm2) - Minute(tm1))

        If j < 0 Then
            i = i - 1
            j = 60 + j
        End If
        CalculateHours = CDec(i & "." & j)
    End Function

Ok Button

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If (CalculateHours(DateTimePicker1.Value, DateTimePicker2.Value) < 0) Then
            MessageBox.Show("Invalid Login / Logout Time", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End If
        Try
            th = 0
            Dim b, fin As Date
            txtOTH.Text = CalculateHours(DateTimePicker1.Value, DateTimePicker2.Value)
            th = (CalculateHours(DateTimePicker1.Value, DateTimePicker2.Value) \ 1 + (((CalculateHours(DateTimePicker1.Value, DateTimePicker2.Value) Mod 1) * 100) / 60))

            st = Today & " " & st.Substring(11)
            b = st

            If CalculateHours(b, DateTimePicker1.Value) > 0 Then
                txtOTH.Text = (CalculateHours(b, DateTimePicker1.Value) \ 1 + ((CalculateHours(b, DateTimePicker1.Value) Mod 1) * 100) / 60)

            End If

            If (Weekday(DateTimePicker3.Value) = 7) Then
                ot = CalculateHours(b.AddHours(5.5), DateTimePicker2.Value)
            Else
                ot = CalculateHours(b.AddHours(wh), DateTimePicker2.Value)
            End If
            txtOTH.Text = ot \ 1 + (((ot Mod 1) * 100) / 60)
            If (Convert.ToDecimal(txtOTH.Text) < 0) Then
                txtOTH.Text = "0.00"
            End If
        Catch ex As Exception

        End Try

    End Sub

i have attached the video link below. which will do this tutorials step by step.

 

admin

Recent Posts

Chat with Claude AI Free – Your Super-Smart AI Buddy

It's like having a super-smart buddy that is always there to help you write stories,…

12 hours ago

Best Festivals UK 2025 [Free Guide Included]

The UK is known for its rich history, diverse culture, and most of all  its…

4 days ago

Bank Holidays 2025 UK – Plan Your Perfect Long Weekends

Do you have a plan for your next holiday? Being aware of the Bank Holidays within the…

4 days ago

Master Cursor AI Full Guide for Students & Creators

The world is rapidly changing of software development AI-assisted tools for coding have become the main focus. As…

4 days ago

Google Gemini AI Free AI Tool for Students & Creators

Google Gemini AI is among the top talked about developments. What exactly is it? What…

5 days ago

Top 5 Reasons You Should Use Grubby AI Humanizer in 2025

As the need for AI content undetectable humanization software skyrockets with more and more AI…

1 week ago