以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]如何获取季度、周的数值?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=107521)

--  作者:hrw68529
--  发布时间:2017/9/29 16:17:00
--  [求助]如何获取季度、周的数值?
如何获取季度和周的数,请专家指教。谢谢

Dim dmm As Date = e.DataRow("起始时间")
e.DataRow("起始时间") = dmm
e.DataRow("年") =dmm.Year
e.DataRow("月") = dmm.Month
e.DataRow("季度") = dmm.Quarter
e.DataRow("周") = dmm.Week

--  作者:有点甜
--  发布时间:2017/9/29 16:24:00
--  

季度

 

e.DataRow("季度") = (dmm.Month-1) \\ 3 + 1

 

周数


Dim s As String = System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(dmm, Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday).ToString

e.DataRow("周") = s

--  作者:hrw68529
--  发布时间:2017/9/29 16:29:00
--  
有点甜,想算一下每个月的第几周,怎么写,谢谢
--  作者:有点甜
--  发布时间:2017/9/29 16:41:00
--  
Dim d As Date = Date.Today
Dim fday As Date = new Date(d.Year, d.Month, 1)
Dim finwek As Integer = fday.DayOfWeek
Dim fwekday As Integer = 7 - (finwek)
Dim diffday As Integer = d.Day - fwekday
diffday = iif(diffday > 0, diffday, 1)
Dim wekInMonth As Integer
If diffday Mod 7 = 0 Then
    wekInMonth = math.Floor(diffday / 7) - 1
Else
    wekInMonth = math.Floor(diffday / 7)
End If
wekInMonth += 1 + iif(d.Day > fwekday, 1, 0)
msgbox(wekInMonth)

--  作者:hrw68529
--  发布时间:2017/9/29 16:46:00
--  
谢谢了,但这个代码怎么用到列“周”里边去呢
--  作者:有点甜
--  发布时间:2017/9/29 16:49:00
--  

Dim d As Date = dmm
Dim fday As Date = new Date(d.Year, d.Month, 1)
Dim finwek As Integer = fday.DayOfWeek
Dim fwekday As Integer = 7 - (finwek)
Dim diffday As Integer = d.Day - fwekday
diffday = iif(diffday > 0, diffday, 1)
Dim wekInMonth As Integer
If diffday Mod 7 = 0 Then
    wekInMonth = math.Floor(diffday / 7) - 1
Else
    wekInMonth = math.Floor(diffday / 7)
End If
wekInMonth += 1 + iif(d.Day > fwekday, 1, 0)

e.DataRow("周") = wekInMonth

--  作者:hrw68529
--  发布时间:2017/9/29 16:54:00
--  
你太强大了,谢谢你


--  作者:hrw68529
--  发布时间:2017/9/30 15:20:00
--  
有点甜,下边的代码能改为自某一个月起,连续计算月数,过了满一年后继续计算,如12,13、14.……………………
如下代码,是你给我的连续计算周的,能改成连续计算月吗

Dim s As String = System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(dmm, Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday).ToString

e.DataRow("连续计算月") = s


--  作者:有点蓝
--  发布时间:2017/9/30 15:41:00
--  
月数直接加减即可

e.DataRow("连续计算月") = e.DataRow("连续计算月")  + 1