Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共4 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:怎么判定上周有购买过电脑,代码要怎么写

1楼
F1216310 发表于:2023/9/5 13:42:00
产品 购买日期
电脑 8.29
电脑 8.30
电脑 9.5
2楼
有点蓝 发表于:2023/9/5 13:52:00
参考:http://www.foxtable.com/webhelp/topics/2720.htm


Dim y As Integer = Date.Today.Year
Dim w As Integer = Date.Today.DayOfWeek '算出今天是星期几
Dim dt1 As Date = Date.Today.AddDays( - w) '获取本周的第一天
Dim dt2 As Date = Date.Today.AddDays(6 - w) '获取本周的最后一天
Dim Filter As String
Filter = "购买日期 >= #" & dt1 & "# And 购买日期 <= #" & dt2 & "#"
msgbox("本周条件:" & Filter)

Dim Filter1 As String = "购买日期 >= #" & dt1.AddDays( - 7) & "# And 购买日期 <= #" & dt2.AddDays( - 7) & "#"
msgbox("上周条件:" & Filter1)
3楼
listfor 发表于:2023/9/5 14:53:00
Imports System.Globalization

Public Sub CheckComputerPurchaseLastWeek()
Dim purchaseRecords As List(Of Dictionary(Of String, Object)) = New List(Of Dictionary(Of String, Object))() From {
New Dictionary(Of String, Object) From {{"product", "电脑"}, {"purchaseDate", New DateTime(2023, 8, 29)}, },
New Dictionary(Of String, Object) From {{"product", "电脑"}, {"purchaseDate", New DateTime(2023, 8, 30)}, },
New Dictionary(Of String, Object) From {{"product", "电脑"}, {"purchaseDate", New DateTime(2023, 9, 5)}, }
}

Dim currentDate As DateTime = DateTime.Now
Dim lastWeekStart As DateTime = currentDate.AddDays(-7).Date.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture)

Dim hasPurchase As Boolean = False

For Each record In purchaseRecords
If record("purchaseDate").ToString("MM/dd/yyyy", CultureInfo.InvariantCulture) >= lastWeekStart Then
hasPurchase = True
Exit For
End If
Next

If hasPurchase Then
Console.WriteLine("上周有购买电脑")
Else
Console.WriteLine("上周没有购买电脑")
End If
End Sub
 
4楼
有点蓝 发表于:2023/9/5 15:04:00
如果是ChatGPT提问的代码,以后建议还是不要发上来了。
共4 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03906 s, 2 queries.