本文介绍了给定日期,如何找到该周的开始日期和结束日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ASP页面允许用户选择日期,它将在该日期的那一周显示报告




我的问题是什么时候程序查询数据库,我需要知道开始

那个星期的日期和结束日期。


任何想法??

My ASP page allows the user select the date, and it will display the report
during that week of that date.

My question is when the program query database, I need to know the beginning
date and ending date of that week.

Any ideas??

推荐答案




<%

''strDate = RS(" Date")

strDate = Date()


strWeekdayName = LCase(WeekdayName(工作日(strDate)))

Dim myDaysArray(7)


myDaysArray(0 )=" monday"

myDaysArray(1)=" tuesday"

myDaysArray(2)=" wednesday"

myDaysArray( 3)=" thursday"

myDaysArray(4)=" friday"

myDaysArray(5)=" saturday"

myDaysArray (6)=" sunday"


对于intLoop = 0到UBound(myDaysArray)


如果strWeekdayName = myDaysArray(intLoop)那么


如果intLoop = 0那么


strStartOfWeekDate = strDate

strEndOfWeekDate = DateAdd(" d",6,海峡日期)


ElseIf intLoop = 6然后


strStartOfWeekDate = DateAdd(" d",-6,strDate)

strEndOfWeekDate = strDate


否则


strStartOfWeekDate = DateAdd(" d", - intLoop,strDate)

strEndOfWeekDate = DateAdd(" d",(6-intLoop),strDate)


结束如果


结束如果


下一页


Response.Write"当前日期:" &安培; strDate& "< br>"

Response.Write" Start Of Week Date:" &安培; strStartOfWeekDate& "< br>"

Response.Write" End Of Week Date:" &安培; strEndOfWeekDate& "< br>"

%>


如果您的''周''周一没有开始,请更改值在阵列中,即




tueday

周三

星期四

星期五

星期六

星期日

星期一


希望这会有所帮助,哦,如果你运行它,因为它应该工作

罚款,从数据库等的顶部注释你的日期,然后

只需删除response.writes在底部。


问候


Rob



<%
'' strDate = RS("Date")
strDate = Date()

strWeekdayName = LCase(WeekdayName(weekday(strDate)))

Dim myDaysArray(7)

myDaysArray(0) = "monday"
myDaysArray(1) = "tuesday"
myDaysArray(2) = "wednesday"
myDaysArray(3) = "thursday"
myDaysArray(4) = "friday"
myDaysArray(5) = "saturday"
myDaysArray(6) = "sunday"

For intLoop = 0 To UBound(myDaysArray)

If strWeekdayName = myDaysArray(intLoop) Then

If intLoop = 0 Then

strStartOfWeekDate = strDate
strEndOfWeekDate = DateAdd("d", 6, strDate)

ElseIf intLoop = 6 Then

strStartOfWeekDate = DateAdd("d", -6, strDate)
strEndOfWeekDate = strDate

Else

strStartOfWeekDate = DateAdd("d", -intLoop , strDate)
strEndOfWeekDate = DateAdd("d", (6-intLoop), strDate)

End If

End If

Next

Response.Write "Current Date : " & strDate & "<br>"
Response.Write "Start Of Week Date : " & strStartOfWeekDate & "<br>"
Response.Write "End Of Week Date : " & strEndOfWeekDate & "<br>"
%>

If your ''week'' doesn''t start on a Monday, change the values in the array, ie
:

tueday
wednesday
thursday
friday
saturday
sunday
monday

Hope this helps, oh and if you run it as it is at the moment it should work
fine, commented line at the top for your date from the database etc, then
just remove the response.writes at the bottom.

Regards

Rob




你不觉得这个类型和版本你正在使用的数据库可能是

相关信息(它是)?


你想在vbscript代码中计算这些日期吗?或者在
数据库查询中?


-

Microsoft MVP - ASP / ASP.NET

请回复新闻组。这个电子邮件帐户是我的垃圾邮件陷阱所以我

不经常检查它。如果你必须离线回复,那么删除

NO SPAM


Don''t you think the type and version of database you are using might be
relevant information (it is)?

Do you want to calculate these dates in the vbscript code? or in the
database query?

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don''t check it very often. If you must reply off-line, then remove the
"NO SPAM"





Arrghh !!你要发布一个2行的SQL语句现在Bob不是你b $ b,这将完全符合Matt想要的并且会让我看起来很糟糕; o)


Rob



Arrghh!! You''re going to post up a 2 line SQL statement now Bob aren''t you
that will do exactly what Matt wants and will make me look bad ;o)

Rob


这篇关于给定日期,如何找到该周的开始日期和结束日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 23:11