时间问题,求代码

baby521 2003-07-06 03:16:52
我想作三个时间选择下拉框,他们分别是:年、月、日。我想实现这样的功能:
当我选择不同的年份、月份後,日子的选择不同。比如说:我选择2000年,2月,则日子的选择是29天,其他是28天
...全文
58 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinguoying 2003-08-09
  • 打赏
  • 举报
回复
year1=trim(Request.form("year1"))
month1=(Request.form("month1"))
day1=(Request.form("day1"))

str10=trim(year1 & "-" & 3 & "-" & 1)

if month1=4 and day1=31 then
day1=30
end if
if month1=6 and day1=31 then
day1=30
end if
if month1=9 and day1=31 then
day1=30
end if
if month1=11 and day1=31 then
day1=30
end if

sql="select datepart(day,convert(datetime,'"&str10&"')-1) as date1"
set date1=objConn.Execute(sql)
if month1=2 and day1>date1("date1") then
set day1=date1("date1")
end if
LonelyStark 2003-07-07
  • 打赏
  • 举报
回复
楼上的也是一个办法
另外
dateadd("d",30,"2--3-7-7")也是一个有用的函数
wjh6of6agriculture 2003-07-07
  • 打赏
  • 举报
回复
昨晚解决了,但今天早上上班忘带了:(
楼主主要是要决定日期问题,我的方法是datediff("n","2002-2-1","2002-3-1").....
楼主懂我的意思吗?还不行的话,晚上回去发给你!!!
wgd 2003-07-07
  • 打赏
  • 举报
回复
up
wjh6of6agriculture 2003-07-07
  • 打赏
  • 举报
回复
代码如下(写都写了,不帖出来不爽,望各路高手指正)
<%
Const BeginYear=1990
Const EndYear=2050
Dim TheYear,TheMonth,TheDay

TheYear=Trim(Request.Form("year"))
TheMonth=Trim(Request.Form("month"))
TheDay=Trim(Request.Form("day"))

Sub GetYear(TempVal)
Dim i
Response.Write "年<select name="&Chr(34)&"year"&Chr(34)&">"&Chr(13)
For i=BeginYear To EndYear
If TempVal<>"" Then
If Cstr(TempVal)=CStr(i) Then
Response.Write "<option selected value="&Chr(34)&CStr(TempVal)&Chr(34)&">"&CStr(i)&"</option>"&Chr(13)
Else
Response.Write "<option value="&Chr(34)&CStr(i)&Chr(34)&">"&CStr(i)&"</option>"&Chr(13)
End If
Else
If Cstr(Year(Date()))=CStr(i) Then
Response.Write "<option selected value="&Chr(34)&CStr(i)&Chr(34)&">"&CStr(i)&"</option>"&Chr(13)
Else
Response.Write "<option value="&Chr(34)&CStr(i)&Chr(34)&">"&CStr(i)&"</option>"&Chr(13)
End If
End If
Next
Response.Write "</select>"&Chr(13)
End Sub

Sub GetMonth(TempVal)
Dim i,j
Response.Write "月<select name="&Chr(34)&"month"&Chr(34)&" onchange=frm.submit()>"&Chr(13)
For i=1 To 12
j=Right("0"&i,2)
If TempVal<>"" Then
If Cstr(TempVal)=CStr(j) Then
Response.Write "<option selected value="&Chr(34)&CStr(TempVal)&Chr(34)&">"&CStr(j)&"</option>"&Chr(13)
Else
Response.Write "<option value="&Chr(34)&CStr(j)&Chr(34)&">"&CStr(j)&"</option>"&Chr(13)
End If
Else
If Cstr(Month(Date()))=CStr(i) Then
Response.Write "<option selected value="&Chr(34)&CStr(j)&Chr(34)&">"&CStr(j)&"</option>"&Chr(13)
Else
Response.Write "<option value="&Chr(34)&CStr(j)&Chr(34)&">"&CStr(j)&"</option>"&Chr(13)
End If
End If
Next
Response.Write "</select>"&Chr(13)
End Sub

Sub GetDay(TempVal)
Dim i,j
Response.Write "日<select name="&Chr(34)&"day"&Chr(34)&">"&Chr(13)
For i=1 To DayNum()
j=Right("0"&i,2)
If TempVal<>"" Then
Response.Write "<option value="&Chr(34)&CStr(j)&Chr(34)&">"&CStr(j)&"</option>"&Chr(13)
Else
If CStr(Day(Date()))=CStr(i) Then
Response.Write "<option selected value="&Chr(34)&CStr(j)&Chr(34)&">"&CStr(j)&"</option>"&Chr(13)
Else
Response.Write "<option value="&Chr(34)&CStr(j)&Chr(34)&">"&CStr(j)&"</option>"&Chr(13)
End If
End If
Next
Response.Write "</select>"&Chr(13)
End Sub

Function DayNum()
Dim TempYear,TempMonth,TempVal
If TheYear="" Then
TempYear=CStr(Year(Date()))
Else
TempYear=TheYear
End If
If TheMonth="" Then
TempMonth=CStr(Month(Date()))
Else
If Cstr(Left(TheMonth,1))="0" Then
TempMonth=Right(TheMonth,1)
Else
TempMonth=TheMonth
End If
End If
BeginDate=CStr(TempYear)&"-"&CStr(TempMonth)&"-1"
If CInt(TempMonth)>11 Then
TempVal=1
TempYear=CInt(TempYear)+1
Else
TempVal=CInt(TempMonth)+1
End If
EndDate=CStr(TempYear)&"-"&CStr(TempVal)&"-1"
DayNum=DateDiff("d",BeginDate,EndDate)
End Function

Response.Write "<form name=frm method=post>"
Call GetYear(TheYear)
Call GetMonth(TheMonth)
Call GetDay(TheDay)
Response.Write "</form>"
%>
baby521 2003-07-06
  • 打赏
  • 举报
回复
to liuyutinglyt(世纪龙二号)
我就是这个意思,你的理解里很不错么。就是我的表达能力差了些!呵呵!
baby521 2003-07-06
  • 打赏
  • 举报
回复
to : wjh6of6agriculture(艰苦奋斗)

这是财务的专业要求,我也没办法。如果能用日历,我早就当一份了,也不必如此费劲了。
ccnucjc 2003-07-06
  • 打赏
  • 举报
回复
自己写个Leap()函数得了,
当年份为闰年时,29
否则为28

也可用VB写个简单的时间控制控件,很简单主要是用一些时间函数,我就曾经写过一个类似于Windows的时间窗口界面,很方便的
LonelyStark 2003-07-06
  • 打赏
  • 举报
回复
day()函数不是可以返回天数么
liuyutinglyt 2003-07-06
  • 打赏
  • 举报
回复
你们怎么能要求人家改变思路呢?
这也是一个技术难关啊,
大家应该帮助解决才对呢。
wjh6of6agriculture 2003-07-06
  • 打赏
  • 举报
回复
同意楼上观点,不如改用日历(JS作的)而且美观大方,我们一直都用它!
jiejifeng 2003-07-06
  • 打赏
  • 举报
回复
这个就是麻烦点,原理是很简单的,但没多大实际用处,还不如直接搞了日期控件呢
liuyutinglyt 2003-07-06
  • 打赏
  • 举报
回复
据我的理解:他是想根据年份和月份求出该月应该有多少天。
dychen 2003-07-06
  • 打赏
  • 举报
回复
什么意思啊!怎么来了个29和28?
liuyutinglyt 2003-07-06
  • 打赏
  • 举报
回复
哎,对了,你的日子的选择是指29被选中,还是指它的值就有29个啊。我想这个差异还是有的吧。以前编过一个,因为不是不适用,就没用。看看我能不能找到啊。
liuyutinglyt 2003-07-06
  • 打赏
  • 举报
回复
呵呵,这我也想要啊。

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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