|
↑
Miscellaneous >>>
This script will print out a date a certain number of days ahead of the current date. Just enter how many days ahead you want to display, and it will print out that date! Useful on order forms (tell a visitor after they order that you must receive their order by a date 3 weeks from today, etc.
Add the below code to the <body> section of your page:
<script
language="javascript"
type="text/javascript">
var
AddDays =
3;
TDate
=
new
Date();
TDay
=
new
Array('Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday');
TMonth
=
new
Array('January',
'February',
'March',
'April',
'May','June',
'July',
'August',
'September',
'October',
'November',
'December');
MonthDays
=
new
Array('31',
'28',
'31',
'30',
'31',
'30',
'31',
'31',
'30',
'31',
'30',
'31');
function
isLeapYear (Year)
{
if
(((Year
%
4)==0)
&&
((Year
%
100)!=0)
||
((Year
%
400)==0))
{
return
true;
}
else
{
return
false;
}
}
CurYear
=
TDate.getYear();
if
(CurYear
<
2000)
CurYear
=
CurYear +
1900;
CurMonth
=
TDate.getMonth();
CurDayOw
=
TDate.getDay();
CurDay
=
TDate.getDate();
month
=
TMonth[CurMonth];
if
(month
==
'February')
{
if
(((CurYear
%
4)==0)
&&
((CurYear
%
100)!=0)
||
((CurYear
%
400)==0))
{
MonthDays[1]
=
29;
}
else
{
MonthDays[1]
=
28;
}
}
days
=
MonthDays[CurMonth];
CurDay
+=
AddDays;
if
(CurDay
>
days)
{
if
(CurMonth
==
11)
{
CurMonth
=
0;
month
=
TMonth[CurMonth];
CurYear
=
CurYear +
1
}
else
{
month
=
TMonth[CurMonth+1];
}
CurDay
=
CurDay -
days;
}
CurDayOw
+=
AddDays;
function
adjustDay (cday)
{
if
(cday
>
6)
{
cday
-=
6;
CurDayOw
=
TDay[cday-1];
adjustDay(cday-1);
}
else
{
CurDayOw
=
TDay[cday];
return
true;
}
}
adjustDay(CurDayOw);
TheDate
=
CurDayOw +
', ';
TheDate
+=
month +
' ';
TheDate
+=
CurDay +
', ';
if
(CurYear<100)
CurYear="19"
+
CurYear;
TheDate
+=
CurYear;
document.write("<center><b>");
document.write(AddDays
+
" days from now is ... "
+
TheDate);
document.write("</b></center>");
</script>
|
→
|