|
Function 日期转周号(y As Date) 'y=现在日期
Dim ss As Date, ksr As Date, yss As Date
nf = Right(Year(y), 2)
ss = Year(y) & "-1-1"
zj = Weekday(ss, 2)
If zj > 4 Then
ksr = ss - zj + 1 + 7
Else
ksr = ss - zj + 1
End If
If y < ksr Then
yss = Year(y) - 1 & "-1-1"
yzj = Weekday(yss, 2)
If yzj > 4 Then
ksr = yss - yzj + 1 + 7
Else
ksr = yss - yzj + 1
End If
nf = nf - 1
End If
xx = Application.WorksheetFunction.RoundUp((y - ksr + 1) / 7, 0)
If Len(xx) < 2 Then xx = "0" & xx
日期转周号 = nf & xx
End Function
'==================================================
Function 周号转日期(xx As String)'计算一周第一天的日期
Dim ss As Date
Dim mss As Date
nh = Left(xx, Len(xx) - 2)
zh = Right(xx, 2)
ss = IIf(nh < 10, "200", "20") & nh & "-1-1"
zj = Weekday(ss, 2)
If zj > 4 Then
ksr = ss - zj + 1 + 7
Else
ksr = ss - zj + 1
End If
mss = IIf(nh < 9, "200", "20") & nh + 1 & "-1-1"
zj = Weekday(mss, 2)
If zj > 4 Then
mksr = mss - zj + 1 + 7
Else
mksr = mss - zj + 1
End If
zs = (mksr - ksr) / 7
If zs < Int(zh) Then
MsgBox "错了"
Else
周号转日期= ksr + 7 * zh - 7
End If
End Function
由于工作原因,我这里的周号用的是1001I(2010年第一周),1002I(2010年第二周),1003I(2010年第三周)......
另外,我是个新手,对于语句结构方面不能很好的控制,可能有的写的啰嗦,欢迎大家指正,修改。 |
|