显示基于周数asp经典的日期

时间:2015-09-19 09:04:36

标签: date asp-classic format

我想根据我从数据库获得的周数来显示周日期。 因此,如果我得到周= 43,那么它将显示该周的所有7个日期。 像这样。

M=23
T=24
W=25
T=26
F=27
S=28
S=29

经过大量日期格式测试但我无法正常工作。 所以任何输入都非常感谢,谢谢!

2 个答案:

答案 0 :(得分:2)

我最终得到了这个,完美无缺!

currentDate = Date
weekNumber=DatePart("ww", currentDate, vbMonday, vbFirstFourDays)
y = Year(Date)

Public Function FirstDayOfWeek(Year, Week)
Dim TempDate

TempDate = DateSerial(Year, 1, 1)
Do Until DatePart("ww", TempDate, vbMonday, vbFirstFourDays) = 1
TempDate = TempDate + 7
Loop

TempDate = TempDate + (7 * (Week - 1))

FirstDayOfWeek = TempDate - Weekday(TempDate, vbMonday) + 1
End Function

Dim startDatum
Dim slutDatum
startDatum = FirstDayOfWeek(y, weekNumber)
slutDatum = startDatum + 6

mon=DatePart("d", startDatum)
tus=DatePart("d", startDatum+1)
wen=DatePart("d", startDatum+2)
tur=DatePart("d", startDatum+3)
fri=DatePart("d", startDatum+4)
sat=DatePart("d", startDatum+5)
sun=DatePart("d", startDatum+6)

答案 1 :(得分:0)

嗯,实际上没有反DatePart()函数,所以你必须进行自己的计算。

dim w, wd, y, m, i
y = Year(Date) '- year of the week in question; I'm using today's date
w = 43
wd = DateAdd("d",w*7,CDate("1/1/" & y)) '- adjust as needed for 1st week of year
m = DateAdd("d",2-Weekday(wd),wd) '- find Monday of week

希望你能从那里出发。