Imports System.Data.OleDb
Public Class Form1
Dim db As String = IO.Path.GetDirectoryName(Application.ExecutablePath) & "\db.accdb"
Dim str As String = "provider=microsoft.ace.oledb.12.0;data source=" & db
Dim con As New OleDbConnection(str)
Dim dt As New DataTable
Dim da As New OleDb.OleDbDataAdapter("select tname,tt from tb", con)
Public Shared Function GetDateSpanText(fromDate As DateTime, toDate As DateTime) As String
Try
Dim days As Integer = 0, hours As Integer = 0, minuts As Integer = 0, sec As Integer = 0
Do Until toDate.AddHours(-1) < fromDate
hours += 1
toDate = toDate.AddHours(-1)
Loop
Do Until toDate.AddMinutes(-1) < fromDate
minuts += 1
toDate = toDate.AddMinutes(-1)
Loop
Do Until toDate.AddSeconds(-1) < fromDate
sec += 1
toDate = toDate.AddSeconds(-1)
Loop
Return String.Format(" {0} س {1} د {2} ث", hours, minuts, sec)
Catch ex As Exception
Return "Error"
End Try
End Function
Function ts(t1 As DateTime, t2 As DateTime) As String
Return GetDateSpanText(t1, t2)
End Function
Sub gd()
dt.Clear()
da.Fill(dt)
Me.DataGridView1.Rows.Clear()
For Each row As DataRow In dt.Rows
Me.DataGridView1.Rows.Add(row(0), row(1))
Next
End Sub
Sub sp()
For Each row As DataGridViewRow In Me.DataGridView1.Rows
If row.IsNewRow = False Then
Me.DataGridView1.Rows(row.Index).Cells(2).Value = ts(Now, CDate(row.Cells(1).Value))
End If
Next
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
gd()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
sp()
End Sub
End Class