ASP Classic - 按天数获取上周的日期

时间:2014-07-01 22:22:46

标签: vbscript asp-classic vb6

例如: 1的日期( 格式:MM / DD / YYYY )是多少?答案是: 6/30/2014

日期编号如下:

Monday=1
...
Friday=5
Sunday=7

这样的事情:

<%
   dim GetPastDay
   GetPastDay=1  
  '^ ^ ^ THIS WOULD MEAN THAT WE ARE LOOKING TO GET PAST/LAST MONDAYS DATE 
  ' AND IF WE WHERE TO REPLACE THE 1 WITH A 5 THEN IT WOULD MEAN PAST/LAST FRIDAY.

   dim GetPastDate
   '** S.O.S. -> I'M STUCK HERE! <- **
%>

最终产出将是:

<%
   Response.write "Last Date for day: " & GetPastDay & " was Date: " & GetPastDate
%>

1 个答案:

答案 0 :(得分:2)

' Test each possible entry from Monday (1) to Sunday (7)...
For i = 1 To 7

    ' Calculate the number of days to subtract from today's date...
    j = (8 - i) Mod 7 + 1

    ' Get the date...
    d = Date - j

    ' Display the date and the weekday...
    MsgBox "Date: " & d & vbCrLf & "Day: " & WeekDayName(WeekDay(d))

Next