Hi all, I’m working on something for my job that requires a script that will display a date x number of business days in the past. (Actually two scripts – one for 3 business days ago, and one for 8 business days ago – but I just need to get one of them done, and I’ll be set!!) I found a script online that will count days in the FUTURE and skip weekends, however, when I tried to modify it to count backwards, it no longer skips weekend days. ? Can someone take a look at my Franken-Script and let me know if I forgot to change a setting or something that will allow it to count backwards and NOT include weekend days? It displays in the format I want already, but it can look as pretty as it wants – it won’t help if the date is wrong! ?
For example, the script below, when run today (Feb 2), returns January 25 – 8 days ago – instead of January 23 – 8 BUSINESS days ago.
<script language=JavaScript>
function getNextBusinessDay() {
return getDeliveryDateObj(-8);
}
function getDeliveryDateObj(businessDaysLeftForDelivery) {
var now = new Date();
var dayOfTheWeek = now.getDay();
var calendarDays = businessDaysLeftForDelivery;
var deliveryDay = dayOfTheWeek + businessDaysLeftForDelivery;
if (deliveryDay >= 6) {
businessDaysLeftForDelivery -= 6 – dayOfTheWeek; //deduct this-week days
calendarDays += 2; //count this coming weekend
deliveryWeeks = Math.floor(businessDaysLeftForDelivery / 5); //how many whole weeks?
calendarDays += deliveryWeeks * 2; //two days per weekend per week
}
now.setTime(now.getTime() + calendarDays * 60
return now;
}
var now = getNextBusinessDay();
var months = new Array(‘January’,’February’,’March’,’April’,’May’,’June’,’July’,’August’,’September’,’October’,’November’,’December’);
var date = ((now.getDate()<10)? “0” : “”)+ now.getDate();
daymonth = months[now.getMonth()]
wkday = date
document.write(“<p align=center><b><font face=Verdana size=1 color=blue>”);
document.write(daymonth);
document.write(“</font><br><font face=Verdana size=6 color=blue>”);
document.write(wkday);
document.write(“</font></b></p>”);
</script>
[CODE]function businessDays(n){
var D=new Date();
var num=Math.abs(n);
var tem,count=0;
var dir= (n<0)? -1: 1;
while(count< num){
D= new Date(D.setDate(D.getDate()+dir));
tem=D.getDay();
if(tem!=0 && tem!=6) ++count;
}
return D;
}[/CODE]
function getDeliveryDateObj(businessDays) {
businessDays = Math.abs(businessDays);
var now = new Date();
var dayOfTheWeek = now.getDay();
if (dayOfTheWeek==0 || dayOfTheWeek==6) { //adjust if start date is a weekend
dayOfTheWeek=(businessDays<0)?1:5;
}
weeks = (businessDays/5);
if (businessDays>0) { //Business days in the future
wholeWeek = Math.floor(weeks);
partsWeek = businessDays-(wholeWeek*5);
if ((dayOfTheWeek+partsWeek)>5) { partsWeek += 2; }
}
if (businessDays<0) { //Business days in the past
wholeWeek = Math.ceil(weeks);
partsWeek = businessDays-(wholeWeek*5);
if ((dayOfTheWeek+partsWeek)<1) { partsWeek -= 2; }
}
var daysToMove = partsWeek + (wholeWeek * 7);
now.setTime(now.getTime() + daysToMove * 24 * 60 * 60 * 1000);
return now;
}
[CODE]function businessDays(n,D){
D= D || new Date();
var num=Math.abs(n);
var tem,count=0;
var dir= (n<0)? -1: 1;
while(count< num){
D= new Date(D.setDate(D.getDate()+dir));
if(D.isHoliday())continue;
tem=D.getDay();
if(tem!=0 && tem!=6) ++count;
}
return D;
}[/CODE]
[CODE]Date.prototype.isHoliday=function(){
var A=[this.getMonth()+1,this.getDate()]
var hol={
'Christmas':[12,25],
'GroundHogDay':[2,2]
}
var tem;
for(var p in hol){
tem= hol[p];
if(A[0]==tem[0] && A[1]==tem[1]) return p;
}
return false;
}[/CODE]
[CODE]$vcs=str_repeat("000000",61);// a string with 366 zeros
$vcs[0]=1; // 1er janvier
$vcs[date('z',easter_date($year)+129600)]=1;// Lundi Pâques
$vcs[date('z',easter_date($year)+38*86400+129600)]=1; // Ascension
$vcs[date('z',easter_date($year)+49*86400+129600)]=1;// Pentecôte
$vcs[date('z',mktime(12,0,0,5,1,$year))]=1; // 1er mai
$vcs[date('z',mktime(12,0,0,5,8,$year))]=1; // 8 mai
$vcs[date('z',mktime(12,0,0,7,14,$year))]=1;// 14 juillet
$vcs[date('z',mktime(12,0,0,8,15,$year))]=1;// 15 août
$vcs[date('z',mktime(12,0,0,11,1,$year))]=1;// 1er novembre
$vcs[date('z',mktime(12,0,0,11,11,$year))]=1;// 11 novembre
$vcs[date('z',mktime(12,0,0,12,25,$year))]=1;// 25 décembre
$cnt = 'var hdy="'.$vcs.'";
file_put_content('hollidays2013.js',cnt);
[/CODE]
[CODE]Date.prototype.getDayOfYear=function(){var a=this.getFullYear(),m=this.getMonth()+1,r=this.getDate();
while(--m) {r+=new Date(a,m,0).getDate();}
return r-1;
}; [/CODE]
<SCRIPT LANGUAGE="JavaScript">
function businessDays10(n,D){
D = D || new Date();
var num=Math.abs(10);
var tem,count=0;
var dir= (n<0)? -1: 1;
while(count< num){
D= new Date(D.setDate(D.getDate()+dir));
if(D.isHoliday())continue;
tem=D.getDay();
if(tem!=0 && tem!=6) ++count;
}
return D;
}
function businessDaysM10(n,D){
D = D || new Date();
var num=Math.abs(10);
var tem,count=0;
var dir= (n<0)? -1: 1;
while(count< num){
D= new Date(D.setDate(D.getDate()+dir));
if(D.isHoliday())continue;
tem=D.getDay();
if(tem!=0 && tem!=6) ++count;
}
return D;
}
Date.prototype.isHoliday=function(){
var A=[this.getMonth()+1,this.getDate()]
var hol={ //Manually update Holiday Dates
'New Years Day':[1,1,2013],
'Martin Luther King, Jr. Day':[1,21,2013],
'Presidents’ Day':[2,18,2013],
'Memorial Day':[5,27,2013],
'Independence Day':[7,4,2013],
'Labor Day':[9,2,2013],
'Columbus Day':[10,14,2013],
'Veterans Day':[11,11,2013],
'Thanksgiving Day':[11,28,2013],
'Christmas':[12,25,2013]
}
var tem;
for(var p in hol){
tem= hol[p];
if(A[0]==tem[0] && A[1]==tem[1]) return p;
}
return false;
}
<span class="style3"><strong><em>Future CALENDAR Dates</em></strong></span><br>
10 Business Days =
<SCRIPT LANGUAGE="JavaScript">
var str = (businessDays10().toLocaleDateString())
document.write (str.fontsize(3))
</script>
</fieldset>
var InputDate;
var SelectDate;
var numDays;
var getDate;
var newDate
var Edate30
var bDate10
EnumDays0 = 0
EnumDays30 = 2592000 //(30 days) 2629743 (1 month=30.44 Days)
function addDate30(dateObject, numDays30) {
dateObject.setDate(dateObject.getDate() + numDays30);
return dateObject.toLocaleDateString();
}
var EdateM30
EnumDaysM30 = -2592000
function addDatem30(dateObject, numDaysm30) {
dateObject.setDate(dateObject.getDate() + numDaysm30);
return dateObject.toLocaleDateString();
}
oldDate = new Date();
oldDate1 = new Date();
numDays30 = 30;
newDate30 = addDate30(oldDate1, numDays30);
function SelectedDate (InputDate, EnumDays) {
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDays0);
Edate0 = new Date (SelectDate *1000);
var eDate0 = (Edate0.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDays30);
Edate30 = new Date (SelectDate *1000);
var eDate30 = (Edate30.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDaysM30);
EdateM30 = new Date (SelectDate *1000);
var eDateM30 = (EdateM30.toLocaleDateString());
oldDateM = new Date();
oldDateM1 = new Date();
numDaysM30 = -(30);
newDateM30 = addDatem30(oldDateM1, numDaysM30);
alert(("The date you selected is " + eDate0) + ("nnFUTURE CALENDAR DATES from your selected date:n30 Days is "+ eDate30) + ("nnPAST CALENDAR DATES from your selected date:n30 Days is ")+ eDateM30);
[CODE]dateObject.setDate(dateObject.getDate() + numDay);[/CODE]
[CODE]
<html lang="en">
<head>
<META name="WebPartPageExpansion" content="full">
<title>Date Calculator</title>
<script src=\"datetimepicker_css.js"></script>
<style type="text/css">
.style1 {
margin-top: 0px;
}
.style2 {
text-align: center;
}
.style3 {
color: #0d2bcc;
}
.style4 {
margin-bottom: 0px;
}
.style5 {
text-align: left;
}
.style6 {
color: #FFFFFF;
}
</style>
</head>
<body>
<table border="0" cellpadding="3"><td valign="top" style="width: 450px">
<fieldset>
<legend class="style3"><span class="style2"><strong><em>CALENDAR DATE CALCULATOR</em></strong></span></legend>
<div class="style2">
<fieldset>
<legend class="style3"><span class="style2"><strong><em>Today's Date</em></strong></span></legend>
<script type="text/javascript" >
var t = new Date();
var ldt = t.toLocaleDateString();
document.write(ldt.bold())
</script>
</fieldset>
<fieldset>
<legend class="style3"><span class="style2"><strong><em>Business Days from Today's Date</em></strong></span></legend>
<body onload="businessDays2()"></body>
<SCRIPT LANGUAGE="JavaScript">
function businessDays2(n,D){
D = D || new Date();
var num=Math.abs(2);
var tem,count=0;
var dir= (n<0)? -1: 1;
while(count< num){
D= new Date(D.setDate(D.getDate()+dir));
if(D.isHoliday())continue;
tem=D.getDay();
if(tem!=0 && tem!=6) ++count;
}
return D;
}
function businessDays10(n,D){
D = D || new Date();
var num=Math.abs(10);
var tem,count=0;
var dir= (n<0)? -1: 1;
while(count< num){
D= new Date(D.setDate(D.getDate()+dir));
if(D.isHoliday())continue;
tem=D.getDay();
if(tem!=0 && tem!=6) ++count;
}
return D;
}
function businessDaysM2(n,D){
D = D || new Date();
var num=Math.abs(-2);
var tem,count=0;
var dir= (n<0)? -1: 1;
while(count< num){
D= new Date(D.setDate(D.getDate()+dir));
if(D.isHoliday())continue;
tem=D.getDay();
if(tem!=0 && tem!=6) ++count;
}
return D;
}
function businessDaysM10(n,D){
D = D || new Date();
var num=Math.abs(-10);
var tem,count=0;
var dir= (n<0)? -1: 1;
while(count< num){
D= new Date(D.setDate(D.getDate()+dir));
if(D.isHoliday())continue;
tem=D.getDay();
if(tem!=0 && tem!=6) ++count;
}
return D;
}
Date.prototype.isHoliday=function(){
var A=[this.getMonth()+1,this.getDate()]
var hol={ //Manually update Holiday Dates
'New Years Day':[1,1,2013],
'Martin Luther King, Jr. Day':[1,21,2013],
'Presidents’ Day':[2,18,2013],
'Memorial Day':[5,27,2013],
'Independence Day':[7,4,2013],
'Labor Day':[9,2,2013],
'Columbus Day':[10,14,2013],
'Veterans Day':[11,11,2013],
'Thanksgiving Day':[11,28,2013],
'Christmas':[12,25,2013]
}
var tem;
for(var p in hol){
tem= hol[p];
if(A[0]==tem[0] && A[1]==tem[1]) return p;
}
return false;
}
</script>
<span class="style3"><strong><em>Future Dates</em></strong></span><br>
2 Business Days =
<SCRIPT LANGUAGE="JavaScript">
var str = (businessDays2(2).toLocaleDateString())
document.write (str.fontsize(3))
</script>
<br>
10 Business Days =
<SCRIPT LANGUAGE="JavaScript">
var str = (businessDays10(10).toLocaleDateString())
document.write (str.fontsize(3))
</script>
<br>
<br><span class="style3"><strong><em>Past Date</em></strong></span><br>
10 Business Days =
<SCRIPT LANGUAGE="JavaScript">
var str = (businessDaysM10(-10).toLocaleDateString())
document.write (str.fontsize(3))
</script>
</fieldset>
<fieldset>
<strong>
<legend class="style3"><span class="style2"><strong><em>Calculated Dates from Today's Date</em></strong></span></legend>
</strong>
<SCRIPT LANGUAGE="JavaScript">
var InputDate;
var SelectDate;
var numDays;
var getDate;
var newDate
var Edate30
var Edate45
var Edate60
var Edate90
EnumDays0 = 0
EnumDays30 = 2592000 //(30 days) 2629743 (1 month=30.44 Days)
EnumDays45 = 3888000 //(45 days)
EnumDays60 = 5184000 //(60 Days) 5259486 (60.87 Days)
EnumDays90 = 7776000 //(90 Days) 7819200 (90.5 Days)
function addDate30(dateObject, numDays30) {
dateObject.setDate(dateObject.getDate() + numDays30);
return dateObject.toLocaleDateString();
}
function addDate45(dateObject, numDays45) {
dateObject.setDate(dateObject.getDate() + numDays45);
return dateObject.toLocaleDateString();
}
function addDate60(dateObject, numDays60) {
dateObject.setDate(dateObject.getDate() + numDays60);
return dateObject.toLocaleDateString();
}
function addDate90(dateObject, numDays90) {
dateObject.setDate(dateObject.getDate() + numDays90);
return dateObject.toLocaleDateString();
}
var EdateM30
var EdateM45
var EdateM60
var EdateM90
EnumDaysM30 = -2592000
EnumDaysM45 = -3888000
EnumDaysM60 = -5184000
EnumDaysM90 = -7776000
function addDatem10(dateObject, numDaysm10) {
dateObject.setDate(dateObject.getDate() + numDaysm10);
return dateObject.toLocaleDateString();
}
function addDatem30(dateObject, numDaysm30) {
dateObject.setDate(dateObject.getDate() + numDaysm30);
return dateObject.toLocaleDateString();
}
function addDatem45(dateObject, numDaysm45) {
dateObject.setDate(dateObject.getDate() + numDaysm45);
return dateObject.toLocaleDateString();
}
function addDatem60(dateObject, numDaysm60) {
dateObject.setDate(dateObject.getDate() + numDaysm60);
return dateObject.toLocaleDateString();
}
function addDatem90(dateObject, numDaysm90) {
dateObject.setDate(dateObject.getDate() + numDaysm90);
return dateObject.toLocaleDateString();
}
oldDate = new Date();
oldDate1 = new Date();
oldDate2 = new Date();
oldDate3 = new Date();
oldDate4 = new Date();
numDays30 = 30;
numDays45 = 45;
numDays60 = 60;
numDays90 = 90;
newDate30 = addDate30(oldDate1, numDays30);
newDate45 = addDate45(oldDate2, numDays45);
newDate60 = addDate60(oldDate3, numDays60);
newDate90 = addDate90(oldDate5, numDays90);
function SelectedDate (InputDate, EnumDays) {
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDays0);
Edate0 = new Date (SelectDate *1000);
var eDate0 = (Edate0.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDays30);
Edate30 = new Date (SelectDate *1000);
var eDate30 = (Edate30.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDays45);
Edate45 = new Date (SelectDate *1000);
var eDate45 = (Edate45.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDays60);
Edate60 = new Date (SelectDate *1000);
var eDate60 = (Edate60.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDays90);
Edate90 = new Date (SelectDate *1000);
var eDate90 = (Edate90.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDaysM30);
EdateM30 = new Date (SelectDate *1000);
var eDateM30 = (EdateM30.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDaysM45);
EdateM45 = new Date (SelectDate *1000);
var eDateM45 = (EdateM45.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDaysM60);
EdateM60 = new Date (SelectDate *1000);
var eDateM60 = (EdateM60.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDaysM90);
EdateM90 = new Date (SelectDate *1000);
var eDateM90 = (EdateM90.toLocaleDateString());
alert(("The date you selected is " + eDate0) + ("nnFUTURE CALENDAR DATES from your selected date:n30 Days is "+ eDate30) + ("n45 Days is ")+ eDate45 + ("n60 Days is ")+ eDate60 + ("n90 Days is ")+ eDate90 + ("nnPAST CALENDAR DATES from your selected date:n30 Days is ")+ eDateM30 + ("n45 Days is ")+ eDate45 + ("n60 Days is ")+ eDate60 + ("n90 Days is ")+ eDateM90);
}
oldDateM = new Date();
oldDateM1 = new Date();
oldDateM2 = new Date();
oldDateM3 = new Date();
oldDateM4 = new Date();
numDaysM30 = -(30);
numDaysM45 = -(45);
numDaysM60 = -(60);
numDaysM90 = -(90);
newDateM30 = addDatem30(oldDateM1, numDaysM30);
newDateM45 = addDatem45(oldDateM2, numDaysM45);
newDateM60 = addDatem60(oldDateM3, numDaysM60);
newDateM90 = addDatem90(oldDateM5, numDaysM90);
</script>
<span class="style3"><strong><em>Future Dates</em></strong></span><br>
<SCRIPT LANGUAGE="JavaScript">
document.write("30 days = " + newDate30 + "");//using computer date
document.write("<br>45 days = " + newDate45 + "");
document.write("<br>60 days = " + newDate60 + "");
document.write("<br>90 days = " + newDate90 + "");
</script>
<br><br><span class="style3"><strong><em>Past Dates</em></strong></span>
<SCRIPT LANGUAGE="JavaScript">
document.write("<br>30 days = " + newDateM30 + "");//using computer date
document.write("<br>45 days = " + newDateM45 + "");
document.write("<br>60 days = " + newDateM60 + "");
document.write("<br>90 days = " + newDateM90 + "");
</SCRIPT>
</fieldset>
<fieldset style="height: 70px" class="style4">
<FORM NAME="myform">
<legend class="style3"><span class="style2"><strong><em>Calculate from Your Own Date</em></strong></span></legend>
<input type="Text" NAME="InputDate" class="style1" onchange="SelectedDate(this.form)" value="Select a Date">
<img src=\"cal.gif" onclick="javascript:NewCssCal('InputDate','mmddyyyy','arrow')" style="cursor:hand"><br>
<input type="reset" value="Reset Calendar">
</form>
[/CODE]
<i>
</i><!DOCTYPE HTML>
<html>
<head>
<title> Fixed & Variable Holidays </title>
<meta charset="utf-8">
</head>
<body>
<div id="debugDIV"></div>
<script type="text/javascript">
// From post #6 of
// http://www.webdeveloper.com/forum/showthread.php?136969-Help-Customizing-Script-to-Subtract-Business-Days-from-Current-Date
function businessDays(n,D){ // counts business days for a different problem
D = D || new Date();
var num = Math.abs(n);
var tem, count = 0;
var dir = (n<0)? -1: 1;
while (count < num) {
D = new Date(D.setDate(D.getDate()+dir));
if ( D.isFixedHoliday() || D.isVariableHoliday() ) { continue; } // bypass count if holiday found
tem = D.getDay(); if(tem != 0 && tem != 6) ++count;
}
return D;
}
Date.prototype.isFixedHoliday=function(){
var A=[this.getMonth()+1,this.getDate()]
var hol = { // fixed dates of year
'New Year':[1,1],
'Ground Hog Day':[2,2],
'Valentine':[2,14],
'Independence Day':[7,4],
'Christmas':[12,25]
}
var tem;
for(var p in hol) {
tem= hol[p]; if(A[0]==tem[0] && A[1]==tem[1]) return p; // not false value if match found
}
return false;
}
Date.prototype.variableDate = function(){
// get month and date - no leading zeroes)
var A=[this.getMonth()+1,this.getDate()];
// weekday from beginning of the month (month/number_of_week/day_of_week)
var n_wday = this.getDay(),
n_wnum = Math.floor((A[1] - 1) / 7) + 1;
var v_date = A[0] + ',' + n_wnum + ',' + n_wday;
return v_date;
}
Date.prototype.isVariableHoliday = function(){
var now = this.variableDate(); // alert(today);
var hol = [ ]; // variable dates of year
/* variable dates of the year */ // Check format = 'month (1-12),week in month (1-5), day of week (0=Sun, 6=Sat.)
// hol['Current Date'] = '8,2,5'; // test entry for today for testing purposes only (change as needed)
hol['MLK BDay'] = '1,3,1'; // Birthday of Martin Luther King, third Monday in January
hol['GW BDay'] = '2,3,1'; // Washington's Birthday, third Monday in February
hol['Armed Forces Day'] = '5,3,6'; // Armed Forces Day, third Saturday in May
hol['Labor Day'] = '9,1,1'; // Labor Day, first Monday in September
hol['Columbus Day'] = '10,2,1'; // Columbus Day, second Monday in October
hol['Thanksgiving'] = '11,4,4'; // Thanksgiving Day, fourth Thursday in November
hol['Black Friday'] = '11,4,5'; // Thanksgiving Day +1, fourth Friday in November
var tem;
for(var p in hol){
tem= hol[p]; if (now == hol[p]) { return p; } // return key if match found (not false value)
}
return false;
}
window.onload = function() {
// sample usage:
var today = new Date();
var debug = document.getElementById('debugDIV');
debug.innerHTML = '<h1> Business Day &amp; Holiday Counter </h1>';
var Dlong = today;
var Dshort = today.toLocaleDateString();
var D1long=businessDays(-3); //string for 3 days before now (today)
var D1short=businessDays(-3).toLocaleDateString(); //string for 3 days before now (today)
var D2long=businessDays(8); //object for 8 business days after now (today)
var D2short=businessDays(8).toLocaleDateString(); //object for 8 business days after now (today)
debug.innerHTML += 'Today: '+Dshort+' is also: '+Dlong; // display for now (today)
debug.innerHTML += '<p>Business days:';
debug.innerHTML += '-3 business days: '+D1short+' is also: '+D1long;
debug.innerHTML += '<br>+8 business days: '+D2short+' is also: '+D2long;
debug.innerHTML += '</p>';
debug.innerHTML += '<p>Today test: '+today.variableDate()+' (month,week,day)'; // current day as a string variable
debug.innerHTML += 'Fixed Holiday? : '+today.isFixedHoliday(); // test for today being a fixed holiday
debug.innerHTML += '<br>Variable Holiday? : '+today.isVariableHoliday(); // test for today being a variable holiday
debug.innerHTML += '</p>';
var str = '<p><b> 30, 45, 60 &amp; 90 BUSINESS days +/- from today</b>';
str += '<br>-90: '+businessDays(-90);
str += '<br>-60: '+businessDays(-60);
str += '<br>-45: '+businessDays(-45);
str += '<br>-30: '+businessDays(-30);
str += '<br>-14: '+businessDays(-14);
str += '<br>-7: '+businessDays(-7);
str += '<br><b>'+today+'</b>';
str += '<br>+7: '+businessDays(7);
str += '<br>+14: '+businessDays(14);
str += '<br>+30: '+businessDays(30);
str += '<br>+45: '+businessDays(45);
str += '<br>+60: '+businessDays(60);
str += '<br>+90: '+businessDays(90);
debug.innerHTML += str+'</p>';
}
</script>
</body>
</html>
[CODE] <script type="text/javascript">
var InputDate;
var SelectDate;
var numDays;
var getDate;
var newDate
var Edate30
var Edate45
var Edate60
var Edate90
EnumDays0 = 0
EnumDays30 = 2592000 //(30 days) 2629743 (1 month=30.44 Days)
EnumDays45 = 3888000 //(45 days)
EnumDays60 = 5184000 //(60 Days) 5259486 (60.87 Days)
EnumDays90 = 7776000 //(90 Days) 7819200 (90.5 Days)
function addDate30(dateObject, numDays30) {
dateObject.setDate(dateObject.getDate() + numDays30);
return dateObject.toLocaleDateString();
}
function addDate45(dateObject, numDays45) {
dateObject.setDate(dateObject.getDate() + numDays45);
return dateObject.toLocaleDateString();
}
function addDate60(dateObject, numDays60) {
dateObject.setDate(dateObject.getDate() + numDays60);
return dateObject.toLocaleDateString();
}
function addDate90(dateObject, numDays90) {
dateObject.setDate(dateObject.getDate() + numDays90);
return dateObject.toLocaleDateString();
}
var EdateM30
var EdateM45
var EdateM60
var EdateM90
EnumDaysM30 = -2592000
EnumDaysM45 = -3888000
EnumDaysM60 = -5184000
EnumDaysM90 = -7776000
function addDatem10(dateObject, numDaysm10) {
dateObject.setDate(dateObject.getDate() + numDaysm10);
return dateObject.toLocaleDateString();
}
function addDatem30(dateObject, numDaysm30) {
dateObject.setDate(dateObject.getDate() + numDaysm30);
return dateObject.toLocaleDateString();
}
function addDatem45(dateObject, numDaysm45) {
dateObject.setDate(dateObject.getDate() + numDaysm45);
return dateObject.toLocaleDateString();
}
function addDatem60(dateObject, numDaysm60) {
dateObject.setDate(dateObject.getDate() + numDaysm60);
return dateObject.toLocaleDateString();
}
function addDatem90(dateObject, numDaysm90) {
dateObject.setDate(dateObject.getDate() + numDaysm90);
return dateObject.toLocaleDateString();
}
oldDate = new Date();
oldDate1 = new Date();
oldDate2 = new Date();
oldDate3 = new Date();
oldDate4 = new Date();
numDays30 = 30;
numDays45 = 45;
numDays60 = 60;
numDays90 = 90;
newDate30 = addDate30(oldDate1, numDays30);
newDate45 = addDate45(oldDate2, numDays45);
newDate60 = addDate60(oldDate3, numDays60);
newDate90 = addDate90(oldDate4, numDays90);
function SelectedDate (InputDate, EnumDays) {
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDays0);
Edate0 = new Date (SelectDate *1000);
var eDate0 = (Edate0.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDays30);
Edate30 = new Date (SelectDate *1000);
var eDate30 = (Edate30.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDays45);
Edate45 = new Date (SelectDate *1000);
var eDate45 = (Edate45.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDays60);
Edate60 = new Date (SelectDate *1000);
var eDate60 = (Edate60.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDays90);
Edate90 = new Date (SelectDate *1000);
var eDate90 = (Edate90.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDaysM30);
EdateM30 = new Date (SelectDate *1000);
var eDateM30 = (EdateM30.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDaysM45);
EdateM45 = new Date (SelectDate *1000);
var eDateM45 = (EdateM45.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDaysM60);
EdateM60 = new Date (SelectDate *1000);
var eDateM60 = (EdateM60.toLocaleDateString());
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDaysM90);
EdateM90 = new Date (SelectDate *1000);
var eDateM90 = (EdateM90.toLocaleDateString());
alert(("The date you selected is " + eDate0) + ("nnFUTURE CALENDAR DATES from your selected date:n30 Days is "+ eDate30) + ("n45 Days is ")+ eDate45 + ("n60 Days is ")+ eDate60 + ("n90 Days is ")+ eDate90 +("nnPAST FUTURE CALENDAR DATES from your selected date:n30 Days is ")+ eDateM30 + ("n45 Days is ")+ eDateM45 + ("n60 Days is ")+ eDateM60 + ("n90 Days is ")+ eDateM90);
}
oldDateM1 = new Date();
oldDateM2 = new Date();
oldDateM3 = new Date();
oldDateM4 = new Date();
numDaysM30 = -(30);
numDaysM45 = -(45);
numDaysM60 = -(60);
numDaysM90 = -(90);
newDateM30 = addDatem30(oldDateM1, numDaysM30);
newDateM45 = addDatem45(oldDateM2, numDaysM45);
newDateM60 = addDatem60(oldDateM3, numDaysM60);
newDateM90 = addDatem90(oldDateM5, numDaysM90);
</script>
[/CODE]
[CODE] <span class="style3"><strong><em>Future CALENDAR Dates</em></strong></span><br>
<script type="text/javascript">
document.write("30 days = " + newDate30 + "");//using computer date
document.write("<br>45 days = " + newDate45 + "");
document.write("<br>60 days = " + newDate60 + "");
document.write("<br>68 days = " + newDate68 + "");
document.write("<br>90 days = " + newDate90 + "");
document.write("<br>118 days = " + newDate118 + "");
</script>
<br><br><span class="style3"><strong><em>Past CALENDAR Dates</em></strong></span>
<script type="text/javascript">
document.write("<br>30 days = " + newDateM30 + "");//using computer date
document.write("<br>45 days = " + newDateM45 + "");
document.write("<br>60 days = " + newDateM60 + "");
document.write("<br>68 days = " + newDateM68 + "");
document.write("<br>90 days = " + newDateM90 + "");
document.write("<br>118 days = " + newDateM118 + "");
</SCRIPT>
[/CODE]
[CODE]
<FORM NAME="myform">
<legend class="style3"><span class="style2"><strong><em>Calculate from Your Own Date</em></strong></span></legend>
<input type="Text" NAME="InputDate" class="style1" onchange="SelectedDate(this.form)" value="Select a Date">
<img src=\cal.gif" onclick="javascript:NewCssCal('InputDate','mmddyyyy','arrow')" style="cursor:hand"><br>
<input type="reset" value="Reset Calendar">
</form>
[/CODE]
Once again I will say: You cannot use document.write statements to change the webpage AFTER it has been rendered.
It will only reload the page with the original contents. Not what you want or expect, I assume.
Also, why are you using 86400 seconds per day when the solution I provided does not use that method at all.
Finally, what is the format of the date returned by your datetimepicker_css? I don't use that particular script.
Rather than mess-up your current webpage design, show a BRIEF example of you datepicker and the code I posted.
Then we can debug your problem and put the corrections into your original page.[/QUOTE]
[CODE]
<script src="\datetimepicker_css.js"></script>
</head>
<body>
<script type="text/javascript">
var Edate0
var InputDate;
var SelectDate;
var numDays;
var getDate;
var newDate
EnumDays0 = 0
oldDate = new Date();
numDays0 = 0
function SelectedDate (InputDate, EnumDays) {
var SelectDate = ((Date.parse(myform.InputDate.value) / 1000) + EnumDays0);
Edate0 = new Date (SelectDate *1000);
var eDate0 = (Edate0.toLocaleDateString());
function addDate0(dateObject, numDays0) {
dateObject.setDate(dateObject.getDate() + numDays0);
return dateObject.toLocaleDateString();
}
alert(("The date you selected is " + eDate0));
}
</script>
<FORM NAME="myform">
<legend class="style3"><span class="style2"><strong><em>Calculate from Your Own Date</em></strong></span></legend>
<input type="Text" NAME="InputDate" class="style1" onchange="SelectedDate(this.form)" value="Select a Date">
<img src="\cal.gif" onclick="javascript:NewCssCal('InputDate','mmddyyyy','arrow')" style="cursor:hand"><br>
<input type="reset" value="Reset Calendar">
</form>
</body>
</html>
[/CODE]
[CODE]
<%@ Page Language="C#" %>
<!DOCTYPE HTML>
<html>
<head>
<META name="WebPartPageExpansion" content="full">
<title> Fixed & Variable Holidays </title>
<meta charset="utf-8">
</head>
<body>
<div id="debugDIV"></div>
<script type="text/javascript">
//Business Days from Today's Date
function businessDays(n,D){ // counts business days for a different problem
D = D || new Date();
var num = Math.abs(n);
var tem, count = 0;
var dir = (n<0)? -1: 1;
while (count < num) {
D = new Date(D.setDate(D.getDate()+dir));
if ( D.isFixedHoliday() || D.isVariableHoliday() ) { continue; } // bypass count if holiday found
tem = D.getDay(); if(tem != 0 && tem != 6) ++count;
}
return D;
}
Date.prototype.isFixedHoliday=function(){
var A=[this.getMonth()+1,this.getDate()]
var hol = { // fixed dates of year
'New Year':[1,1],
'Ground Hog Day':[2,2],
'Valentine':[2,14],
'Independence Day':[7,4],
'Christmas':[12,25]
}
var tem;
for(var p in hol) {
tem= hol[p]; if(A[0]==tem[0] && A[1]==tem[1]) return p; // not false value if match found
}
return false;
}
Date.prototype.variableDate = function(){
// get month and date - no leading zeroes)
var A=[this.getMonth()+1,this.getDate()];
// weekday from beginning of the month (month/number_of_week/day_of_week)
var n_wday = this.getDay(),
n_wnum = Math.floor((A[1] - 1) / 7) + 1;
var v_date = A[0] + ',' + n_wnum + ',' + n_wday;
return v_date;
}
Date.prototype.isVariableHoliday = function(){
var now = this.variableDate(); // alert(today);
var hol = [ ]; // variable dates of year
/* variable dates of the year */ // Check format = 'month (1-12),week in month (1-5), day of week (0=Sun, 6=Sat.)
// hol['Current Date'] = '8,2,5'; // test entry for today for testing purposes only (change as needed)
hol['MLK BDay'] = '1,3,1'; // Birthday of Martin Luther King, third Monday in January
hol['GW BDay'] = '2,3,1'; // Washington's Birthday, third Monday in February
hol['Armed Forces Day'] = '5,3,6'; // Armed Forces Day, third Saturday in May
hol['Labor Day'] = '9,1,1'; // Labor Day, first Monday in September
hol['Columbus Day'] = '10,2,1'; // Columbus Day, second Monday in October
hol['Thanksgiving'] = '11,4,4'; // Thanksgiving Day, fourth Thursday in November
hol['Black Friday'] = '11,4,5'; // Thanksgiving Day +1, fourth Friday in November
var tem;
for(var p in hol){
tem= hol[p]; if (now == hol[p]) { return p; } // return key if match found (not false value)
}
return false;
}
window.onload = function() {
// sample usage:
var today = new Date();
var debug = document.getElementById('debugDIV');
debug.innerHTML = '<h2><i>Check Fraud Important Date Calculator</i></h2>';
var Dshort = today.toLocaleDateString();
var D1short=businessDays(2).toLocaleDateString(); //string for 3 days after now (today)
var D2short=businessDays(10).toLocaleDateString(); //object for 8 business days after now (today)
var D3short=businessDays(-10).toLocaleDateString(); //object for 10 business days before now (today)
//Calendar Days from Today's date
function calDays(n,C) {
C = C || new Date();
var num = Math.abs(n);
var tem, count = 0;
var dir = (n<0)? -1: 1;
while (count < num) {
C = new Date(C.setDate(C.getDate()+dir));
tem = C.getDay(); if(tem != -1 && tem != 7) ++count;
}
return C;
}
debug.innerHTML += '<i><h3>Today's Date:</h3></i> '+Dshort; // is also: '+Dlong; // display for now (today)
debug.innerHTML += '<i><h4>Business days from Today's Date<br> - Future Date</h4></i>';
debug.innerHTML += '2 business days: '+D1short; //+' is also: '+D1long;
debug.innerHTML += '<br>10 business days: '+D2short; //+' is also: '+D2long;
debug.innerHTML += '<p><h4><i><b>- Past Dates </b></i></h4>';
debug.innerHTML += '10 business days: '+D3short;
}
</script>
</body>
</html>
[/CODE]
I...
The datepicker_ccs.js is 1341 lines so if I included it on this post the post would not be brief.
The datepicker_ccs.js uses Epoch time to determine the selected date.
In order to allow a user to select a date and to display the selected date I am using the following code:
[CODE]
<script src="\datetimepicker_css.js"></script>
...
[/CODE]
I hope I included everything you are looking for.[/QUOTE]
Since you cannot post because of the size, can you provide a link to the datetimepicker_css.js script?
If not, can you provide a live link to your program for testing?[/QUOTE]
[CODE]
<html>
<head>
<META name="WebPartPageExpansion" content="full">
<title> Fixed & Variable Holidays </title>
<meta charset="utf-8"> <script src="\datetimepicker_css.js"></script>
<style type="text/css">
.style1 {
margin-top: 0px;
}
.style2 {
text-align: center;
}
.style3 {
color: #0d2bcc;
}
.style4 {
margin-bottom: 0px;
}
.style5 {
text-align: left;
}
.style6 {
color: #FFFFFF;
}
</style>
</head>
<body>
<script type="text/javascript">
var Edate
var InputDate;
numDays0 = 0
function SelectedDate (InputDate) {
var InputDate
var SelectDate = Date.parse(myform.InputDate.value);
Edate = new Date (SelectDate);
var eDate = (Edate.toLocaleDateString());
//Calendar Days from Selected date
function ScalDays(n,S) {
S = S || new Date(SelectedDate);
var num = Math.abs(n);
var tem, count = 0;
var dir = (n<0)? -1: 1;
while (count < num) {
S = new Date(S.setDate(S.getDate()+dir));
tem = S.getDay(); if(tem != -1 && tem != 7) ++count;
}
return S;
}
var D9short=ScalDays(30).toLocaleDateString(); //object for 30 calendar days after now (Selected)
alert(("The date you selected is " + eDate) + "nnFUTURE CALENDAR DATES from your selected date:n30 Days is "+ D9short);
}
</script>
<fieldset style="height: 70px; width: 316px;" class="style4">
<FORM NAME="myform" style="width: 308px">
<legend class="style3"><span class="style2"><strong><em>Calculate from Your Own Date</em></strong></span></legend>
<input type="Text" NAME="InputDate" class="style1" onchange="SelectedDate(this.form)" value="Select a Date">
<img src=/cal.gif" onclick="javascript:NewCssCal('InputDate','mmddyyyy','arrow')" style="cursor:hand"><br>
<input type="reset" value="Reset Calendar">
</form>
</fieldset>
</body>
</html> [/CODE]
0.1.9 — BETA 5.18