ASP Classic - Get last weeks date by day number

2019-09-20 06:58发布

问题:

For example: What was the Date (format: MM/DD/YYYY) for 1? and the answer would be: 6/30/2014

Day number works like this:

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

So something like this:

<%
   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! <- **
%>

THE FINAL OUTPUT WOULD BE:

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

回答1:

' 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