Home > front end >  Asp to generate arbitrary random date 05-08 years, the function code usage how to write?
Asp to generate arbitrary random date 05-08 years, the function code usage how to write?

Time:12-05

Watching a quiz on BBS "asp generated 05-08 years arbitrarily date" written as follows, but the function usage how to write, Montana, please grant instruction, online etc.! Attached to the link https://bbs.csdn.net/topics/290083872


<%
Randomize
Sdate=int (Rnd * 3 + 2005)
Randomize
Sdate=sdate & amp; "-" & amp; Int (Rnd * 11 + 1)
Randomize
Sdate=sdate & amp; "-" & amp; Int (Rnd * 30 + 1)
If isDate (sdate) then
Response. Write sdate
End the if
% & gt;

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Above problem resolved:

<%
The Function sdate '//Function name
Randomize
Sdate=int (Rnd * 3 + 2005) '//random year 2005-2008
Randomize
Sdate=sdate & amp; "-" & amp; Right (" 0 "& amp; Int (Rnd * 11 + 1), 2) 'in//
Randomize
Sdate=sdate & amp; "-" & amp; Right (" 0 "& amp; Int (Rnd * 30 + 1), 2) '//date
End the Function
% & gt;

Usage:
<% %=sdate & gt;

CodePudding user response:

This does not ensure that date

CodePudding user response:

 Function getRndDate (byval s, byval e) 
Randomize
GetRndDate=Cdate (DateAdd (" d ", int * e (RND), s))
End the Function
Response. Write getRndDate (" 2005-1-1 ", 365 * 4)

CodePudding user response:

reference 1st floor hookee response:
this date does not guarantee legal

Isdate () done judgment with respect to OK

CodePudding user response:

<script runat="server" language="livescript & gt;"
The function getRandDay (start, days) {
Var date=new date (start);
Var rand=Math. Floor (Math. The random () * days);
Date. SetDate (date, getDate () + rand);
The return date. GetVarDate ();
}
</script>
<%=getRandDay (" 2005/01/01 ", 365 * 3) % & gt;
  •  Tags:  
  • ASP
  • Related