怎么查询出字本周过生日的用户?

ynxuzhao 2005-10-30 12:53:42
如题,难点在于本周存在跨月、年,以及2月的问题。
...全文
95 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zy51 2005-10-30
  • 打赏
  • 举报
回复
<%
today=date
if weekday(today)=1 then today=DateAdd("d", -6, today)
if weekday(today)=2 then today=today
if weekday(today)=3 then today=DateAdd("d", -1, today)
if weekday(today)=4 then today=DateAdd("d", -2, today)
if weekday(today)=5 then today=DateAdd("d", -3, today)
if weekday(today)=6 then today=DateAdd("d", -4, today)
if weekday(today)=7 then today=DateAdd("d", -5, today)

'取得周一和周末的日期
strtoday=right(Format_date(today),5)
today1=DateAdd("d",6,today)
strtoday1=right(Format_date(today1),5)

if mid(strtoday1,1,2)=01 and mid(strtoday,1,2)=12 then
sql="SELECT count(*) as total from [birthday] where right(left(convert(char,client_birthday,21),10),5) between '01-01' and '"&strtoday1&"'"
sql1="select count(*) as total from [birthday] where right(left(convert(char,client_birthday,21),10),5) between '"&strtoday&"' and '12-31'"
set rs=conn.execute(sql)
set rs1=conn.execute(sql1)
response.write "共有"&rs("total")+rs1("total")&"人过生日"
else
sql="SELECT count(*) as total from [birthday] where right(left(convert(char,client_birthday,21),10),5) between '"&strtoday&"' and '"&strtoday1&"'"
set rs=conn.execute(sql)
response.write "共有"&rs("total")&"人过生日"
end if

Function Format_date(str)
Dim y, m, d, h, mi, s
Format_date = ""
If IsDate(str) = False Then Exit Function
y=year(str)
m=right("0"&month(str),2)
d=right("0"&day(str),2)
Format_date = y & "-" & m & "-" & d
End Function
%>

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧