ASP经典 - 查找上周周五或使用天数作为任何一天(1-7,1 =周一等等..) [英] ASP Classic - Find last weeks Friday or any day using days as numbers (1-7, 1=Monday and so on..)

查看:303
本文介绍了ASP经典 - 查找上周周五或使用天数作为任何一天(1-7,1 =周一等等..)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到上周的周五为例。
使用天为编号(1至7)例如:

  1 =周一等等..

这将是这样的,但我被困在GetLastWeek,请参见下面,谢谢。

 <%
昏暗的WEEKNUM
WEEKNUM = 5昏暗的GetLastWeek
GetLastWeek = ???? < == FIND上周星期五为日期如:MM / DD / YYYY
%GT;例如:上周的周五上:其中,%= GetLastWeek%GT;


解决方案

我可能是要找出何处是一周中的当前日期和工作从那里回来,你可以使用这样的事情开始;

暗淡的今天,offsetdays,lastfri
工作日()返回1 - 7(星期日 - 星期六)。
今日=工作日(DATE())锻炼偏移然后用使用DateAdd()来减去的天数。
今天选择案例
案例1星期日
  offsetdays = 2
案例2星期一
  offsetdays = 3
案例3'周二
  offsetdays = 4
案例4周三
  offsetdays = 5
案例5'星期四
  offsetdays = 6
案例6'星期五
  offsetdays = 7
案例7'星期六
  offsetdays = 1
结束选择lastfri =使用DateAdd(D,-offsetdays,日期())


请记住,这是伪codeD(未经测试),并很可能在阵列中存储的偏移量,并使用该给力使用DateAdd()代替。

I would like to find last weeks Friday for example. Using days as numbers (1 through 7) for example:

1= Monday and so on..

It would be something like this but I'm stuck at the GetLastWeek, Please see below, THANKS.

<%
dim weeknum
weeknum=5

dim GetLastWeek
GetLastWeek=???? <== FIND LAST WEEKS FRIDAY AS A DATE Eg: MM/DD/YYYY
%>

Example: Last weeks Friday was on: <%=GetLastWeek%>

解决方案

I probably start by working out what is the current day of the week and working back from there, you can use something like this;

Dim today, offsetdays, lastfri
'WeekDay() returns 1 - 7 (Sunday - Saturday).
today = WeekDay(Date())

'Workout the offset then use DateAdd() to minus that number of days.
Select Case today
Case 1 'Sunday
  offsetdays = 2
Case 2 'Monday
  offsetdays = 3
Case 3 'Tuesday
  offsetdays = 4
Case 4 'Wednesday
  offsetdays = 5
Case 5 'Thursday
  offsetdays = 6
Case 6 'Friday
  offsetdays = 7
Case 7 'Saturday
  offsetdays = 1
End Select

lastfri = DateAdd("d", -offsetdays, Date())


Bear in mind this is pseudo coded (untested) and could probably be made better by storing the offsets in an array and using that to power the DateAdd() instead.

这篇关于ASP经典 - 查找上周周五或使用天数作为任何一天(1-7,1 =周一等等..)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆