我想从已经在数据库中输入的日期开始每两周创建一个任务提醒(用户将其添加到具有开始日期点的数据库)。根据一周中的一天的位置,我试了一下,但没有用,如果有人有想法我会很感激
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“??????”我不知道我能拿什么来获得正确的结果!!请有人帮帮我!
答案 0 :(得分:0)
正如我从您的评论中所理解的,您只对区间分析部分感兴趣,即确定今天的日期是否在数据库中定义的给定条件之前/之后(使用start_date
和{ {1}})。这里有一个示例代码来处理这个问题:
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
天数。