# ASP以周一作为每周第一天，如何指定日期计算是当年第几周？

xiaosong2008 2015-03-02 11:53:23

'定义本周和下周年份，及本周和下周的周数
dim y,y1,n,n1
y=cint(year(date()))
n=DatePart("ww", date())
'判断下周日日期，以确定下周是否属于本年度
a=DatePart("w", Date) - 1
b=7-a
if year(c)=year(date()) then
y1=cint(year(date()))
n1=n+1
else
y1=cint(year(date()))+1
n1=1
end if

...全文
379 5 打赏 收藏 转发到动态 举报

5 条回复

hookee 2015-03-04
• 打赏
• 举报

``````
Function GetNthWeek(sDate)
Dim dt, daysElapsed, wd, n
dt = CDate(sDate)
daysElapsed = DateDiff("d", Year(dt) & "-1-1", dt)
wd = Weekday(CDate(Year(dt) & "-1-1"), 2)
If  wd = 1 Then
n = daysElapsed \ 7
If (daysElapsed Mod 7) <> 0 Then n = n + 1
Else
If daysElapsed < (7 - wd + 1) Then
n = 1
Else
daysElapsed = daysElapsed - (7 - wd + 1) + 1
n = (daysElapsed \ 7) + 1
If (daysElapsed Mod 7) <> 0 Then n = n + 1
End If
End If
GetNthWeek = n
End Function
``````
xiaosong2008 2015-03-03
• 打赏
• 举报

``````

Response.Write GetNthWeek("2015-1-5")
Response.Write GetNextMondy("2015-1-6")

Function GetNthWeek(sDate)
Dim dt, daysElapsed, wd, n
dt = CDate(sDate)
daysElapsed = DateDiff("d", Year(dt) & "-1-1", dt)
wd = Weekday(CDate(Year(dt) & "-1-1"), 2)
If  wd = 1 Then
n = daysElapsed \ 7
If (daysElapsed Mod 7) <> 0 Then n = n + 1
Else
If daysElapsed < wd Then
n = 1
Else
daysElapsed = daysElapsed - (wd - 1)
n = (daysElapsed \ 7) + 1
If (daysElapsed Mod 7) <> 0 Then n = n + 1
End If
End If
GetNthWeek = n
End Function

Function GetNextMondy(sDate)
Dim dt, wd
dt = CDate(sDate)
wd = Weekday(dt, 2)
End Function

``````

hookee 2015-03-03
• 打赏
• 举报

``````

Response.Write GetNthWeek("2015-1-5")
Response.Write GetNextMondy("2015-1-6")

Function GetNthWeek(sDate)
Dim dt, daysElapsed, wd, n
dt = CDate(sDate)
daysElapsed = DateDiff("d", Year(dt) & "-1-1", dt)
wd = Weekday(CDate(Year(dt) & "-1-1"), 2)
If  wd = 1 Then
n = daysElapsed \ 7
If (daysElapsed Mod 7) <> 0 Then n = n + 1
Else
If daysElapsed < wd Then
n = 1
Else
daysElapsed = daysElapsed - (wd - 1)
n = (daysElapsed \ 7) + 1
If (daysElapsed Mod 7) <> 0 Then n = n + 1
End If
End If
GetNthWeek = n
End Function

Function GetNextMondy(sDate)
Dim dt, wd
dt = CDate(sDate)
wd = Weekday(dt, 2)
End Function

``````
xiaosong2008 2015-03-02
• 打赏
• 举报

ysf0181 2015-03-02
• 打赏
• 举报

28,376

• 近7日
• 近30日
• 至今