ใช้ DateDiff หาวันที่เกิน แล้วไป x ค่าปรับต่อวันได้เลยครับ
Code (VB.NET)
Dim datTim1 As Date = #1/4/2001#
Dim datTim2 As Date = #1/9/2001#
' Assume Sunday is specified as first day of the week.
Dim wD As Long = DateDiff(DateInterval.Weekday, datTim1, datTim2)
Dim wY As Long = DateDiff(DateInterval.WeekOfYear, datTim1, datTim2)
Private Sub DataGridView1_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
Dim i As Integer
i = DataGridView1.CurrentRow.Index
Dim B_ID As Integer
B_ID = Convert.ToUInt32(DataGridView1.Item(1, i).Value)
StrSQL = "INSERT INTO renttmp1(Barcode_ID,DateOver)VALUES(" & B_ID & ", NOW())"
ds = New DataSet
da = New MySqlDataAdapter(StrSQL, MySQLConn)
da.Fill(ds, "renttmp1")
Call UpdateOverDays()
'MsgBox("Insert complete!")
MySQLConn.Close()
Me.Close()
End Sub
Sub UpdateOverDays()
StrSQL = "UPDATE renttmp1 SET OverDays = DATEDIFF(now(),DateOver) WHERE ID"
ds = New DataSet
da = New MySqlDataAdapter(StrSQL, MySQLConn)
da.Fill(ds, "renttmp1")
End Sub
Dim i As Integer
i = DataGridView1.CurrentRow.Index
Dim B_ID As Integer
Dim D_ID As Date
B_ID = Convert.ToUInt32(DataGridView1.Item(1, i).Value)
D_ID = CDate(DataGridView1.Item(8, i).Value)
StrSQL = "INSERT INTO renttmp1(Barcode_ID,DateEnd,DateOver)VALUES(" & B_ID & "," & D_ID & ", Now())"
ds = New DataSet
da = New MySqlDataAdapter(StrSQL, MySQLConn)
da.Fill(ds, "renttmp1")