Using Datagrid to indicate range of dates
-
Hi I am using a datagrid to indicate employes that are on leave iver a certain period. The code works well for employees that take leave more then one day. The problem arises when the employee only takes one day leave, the datagrid shows the day of leave and every other day up until the end of the array. Please help
For i = 0 To oDS.Tables("Dept_History").Rows.Count - 1 dr = dt.NewRow() dr(0) = oDS.Tables("Dept_History").Rows(i).Item("Name").ToString() iCol = 1 For m = Month(NewStartD) To Month(NewEndD) If m = Month(NewEndD) Then lastday = Day(NewEndD) Else lastday = Darray(m) End If If m = Month(NewStartD) Then startday = Day(NewStartD) Else startday = 1 End If For d = startday To lastday Dim CheckDate As Date Dim SD As String Dim ED As String Dim ld As Long Dim FDate As New Date(Year(NewEndD).ToString(), m.ToString(), d.ToString()) 'FDate = m.ToString() & "/" & d.ToString() & "/" & Year(NewEndD).ToString() ED = oDS.Tables("Dept_History").Rows(i).Item("EDate").ToString() SD = oDS.Tables("Dept_History").Rows(i).Item("SDate").ToString() ld = DateDiff(DateInterval.Day, CDate(ED), CDate(SD)) If DateDiff(DateInterval.Day, CDate(FDate), CDate(SD)) = 0 Then dr(iCol) = d.ToString() ElseIf DateDiff(DateInterval.Day, CDate(FDate), CDate(ED)) = 0 Then dr(iCol) = d.ToString() Else dr(iCol) = "0" End If iCol = iCol + 1 Next d Next m dt.Rows.Add(dr) Next i Dim dv As New Dat