0

I want to create a task reminder (which the user add it to the database with a start date spot) every two weeks from the date already entered in the database. Based on the position of the day in the week, I made a try but to no avail, if someone has an idea I would be grateful

cmd5.CommandText = "select * from task where frequence='2W' "
    da5.SelectCommand = cmd1
    da5.Fill(ds5, "0")
    DataGridView6.Columns.Add("fr", "fr")
    DataGridView6.Columns.Add("class", "class")

    For i As Integer = 0 To ds5.Tables(0).Rows.Count - 1
        If Date.Now.DayOfWeek > 3 Then
            If CType(ds5.Tables(0).Rows(i).Item(3), Date).DayOfWeek = Date.Now.DayOfWeek Or CType(ds5.Tables(0).Rows(i).Item(3), Date).DayOfWeek - ???? = Date.Now.DayOfWeek Then
                DataGridView6.Rows.Add(ds5.Tables(0).Rows(i).Item(4), CType(ds5.Tables(0).Rows(i).Item(3), Date).DayOfWeek)
            End If
        End If
        If Date.Now.DayOfWeek < 4 And Date.Now.DayOfWeek <> 0 Then
            If CType(ds5.Tables(0).Rows(i).Item(3), Date).DayOfWeek = Date.Now.DayOfWeek Or CType(ds5.Tables(0).Rows(i).Item(3), Date).DayOfWeek + ???? = Date.Now.DayOfWeek Then
                DataGridView6.Rows.Add(ds5.Tables(0).Rows(i).Item(4), CType(ds5.Tables(0).Rows(i).Item(3), Date).DayOfWeek)
            End If
        End If
    Next

in "??????" I don't know what i can put to obtain the correct results !! can someone help me please !

4

1 回答 1

0

正如我从您的评论中了解到的那样,您只对区间分析部分感兴趣,即确定今天的日期是否在数据库中定义的给定条件之前/之后(使用start_dateand frequency)。在这里,您有一个示例代码来处理这个问题:

Dim start_date As Date = Now.AddDays(-14) 'start_date value to be taken from the DB
Dim frequency As TimeSpan = TimeSpan.FromDays(14) 'Number of days as a function of the given frequency in your DB; this is for 2W.
Dim elapsedDays As TimeSpan = Now.Subtract(start_date)

If (elapsedDays >= frequency) Then
    'NOTIFY USER -> it has passed, at least, "frequency" number of days from "start_date"
    If (elapsedDays > frequency) Then
        Dim addDays As Integer = elapsedDays.Subtract(frequency).Days
        Dim dateWhenTargetMet As Date = Now.AddDays(-addDays)
        'Tell user that the target was met "addDays" ago, on "dateWhenTargetMet" 
    End If
End If

上面的代码检查当前日期是否等于(或晚于)start_date+frequency天数。

于 2013-09-01T15:08:44.393 回答