JavaScript - I Need Help With A Due Date (skip Weekends)
I feel silly asking this (because I'm no good with Java) but I need assistance to set a due date and get it to count past the weekend. I had a couple of Java classes forever ago and it's not my forte, but at any rate I have to adjust the code in a program that I maintain at work. I need to keep it simple because in 6 months when I need to update it I will never remember what I did because it's not something I do enough to retain the skills.
Code: var today = new Date(); var duedate = today.setDate(today.getDate()+2); taskform.datefield.DataValue = duedate; I tried an if/else then a when and I bombed at both I figured I was going to have to actually write something. I'm smart enough to know I won't get this on my own, especially if I have to get an array going. Thank you all who have the patients to try and assist we dipsticks who get in over our heads!!! L Similar Tutorialsdoes anyone know of a timepicker that i can disable weekends and bank holidays (or that at least easily has a place i can add code to disable days by making a call to my database of holidays in ajax?) Site in question: www.yourvancouvermortgagebroker.ca/apply On the 3rd step of this form, I want to add a "SKIP" button that will send the user to the 5th step. No clue how to do this, as someone else helped me code. Thank You! Relevant code javascript file: Code: //step 3 $('#submit_third').click(function(){ //remove classes $('#third_step input').removeClass('error').removeClass('valid'); //ckeck if inputs aren't empty var fields = $('#third_step input[type=text]'); var error = 0; fields.each(function(){ var value = $(this).val(); if( value.length<1 || value==field_values[$(this).attr('id')] || ( $(this).attr('id')=='cemail' && !emailPattern.test(value) ) ) { $(this).addClass('error'); $(this).effect("shake", { times:3 }, 50); error++; } else { $(this).addClass('valid'); } }); if(!error) { //update progress bar $('#progress_text').html('60% Complete'); $('#progress').css('width','204px'); //slide steps $('#third_step').slideUp(); $('#fourth_step').slideDown(); } else return false; }); //step 4 $('#submit_fourth').click(function(){ //remove classes $('#fourth_step input').removeClass('error').removeClass('valid'); var fields = $('#fourth_step input[type=text]'); var error = 0; fields.each(function(){ var value = $(this).val(); if( value.length<1 || value==field_values[$(this).attr('id')]) { $(this).addClass('error'); $(this).effect("shake", { times:3 }, 50); error++; } else { $(this).addClass('valid'); } }); if(!error) { //update progress bar $('#progress_text').html('80% Complete'); $('#progress').css('width','272px'); //slide steps $('#fourth_step').slideUp(); $('#fifth_step').slideDown(); } }); // step 5 $('#submit_fifth').click(function(){ //remove classes $('#fifth_step input').removeClass('error').removeClass('valid'); I need to figure out the on page button code, what I need to add to the javascript file AND what I need to add in the CSS. (css is here) Thank you SO much to whoever can help. Not sure if this is possible in javascript: I'm looking for two different dates (bill date and due date) on an invoice that are captured by OCR. If one of them exists, but the other does not, I want the empty field to be 14 days before (or after) the other. For example: if the bill date is 7/27/2010 and the due date was not captured, I want to set the due date as 8/10/2010 (14 days after the bill date). If the due date was captured as 8/10/2010, but the due date is blank, I want to assign the bill date as 7/27/2010 (14 days before the due date). if both dates have values, do nothing. Thanks. Hi, I need to add days to a date in javascript, My requirement is as follows: Date is coming from a textbox. eg:- 26/07/2010 days from this statement var day1=document.getElementById('<%=HiddenDate.ClientID %>').value; an eg:- if the date is 28/01/2012 and days Needed to be added=5 the added date should be 02/02/2012. Can anybody help me? Thanks Jamuna Using Adobe Form Javascript validation, how would I do this code for Visual Basic in Javascript (non web) Code: If PurchaseDate.Value > Date Then MsgBox ("PurchaseDate cannot be greater than Today's Date!") Cancel = True End If Something along these lines but this isnt working: Code: If (PurchaseDate.Value > Date) Then { app.alert ("Purchase Date cannot be greater than Today's Date!"); } Thanks Hi, I've inherited a Form which calculates a future date based on a calculation and then inserts today's date and the future date into a database. The day part of the date is formatted as a number. This is fine, but up to 9 the numbers display in single figures with no leading zeros. I want them to display leading zeros (e.g. 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11... 30, 31) So; 1/12/2010 is NOT wanted 01/12/2010 IS wanted The inherited code originally set the Month names as "Jan", "Feb" etc, and it was easy to kludge these to 01, 02... 12, but I suspect there's a more elgant solution to this as well, this bit of the code works so it's not as vital to neaten this but my database needs dd/mm/yyyy format (it's a third party email program). Code: </script> <script type="text/javascript"> var todaysDate = new Date(); function updateExpiryDate(){ var weeklyMileage = document.getElementById('AvWeeklyMileage').value; var expiryDate; var weeks = 0; var expiryDateString = ''; if (!isNaN(parseInt(weeklyMileage))){ weeks = 700/weeklyMileage; expiryDate = new Date(todaysDate.getTime() + (1000 * 3600 * 24 * 7 * weeks)); var expiryDateString = expiryDate.getDate() + '/' + getMonthString(expiryDate.getMonth()+1) + '/' + expiryDate.getFullYear(); document.getElementById('expiryDate').innerHTML = expiryDateString; document.getElementById('ShoeExpiryDate').value = expiryDateString; } else { document.getElementById('ShoeExpiryDate').value = ''; document.getElementById('expiryDate').innerHTML = 'Please enter a valid weekly average mileage' } } function getMonthString(monthNumber){ var monthString = ""; switch(monthNumber){ case 1: monthString = "01"; break; case 2: monthString = "02"; break; case 3: monthString = "03"; break; case 4: monthString = "04"; break; case 5: monthString = "05"; break; case 6: monthString = "06"; break; case 7: monthString = "07"; break; case 8: monthString = "08"; break; case 9: monthString = "09"; break; case 10: monthString = "10"; break; case 11: monthString = "11"; break; case 12: monthString = "12"; break; default: // do nothing; } return monthString; } function setTodaysDate(){ var todaysDateString = todaysDate.getDate() + '/' + getMonthString(todaysDate.getMonth()+1) + '/' + todaysDate.getFullYear(); document.getElementById('todaysDate').innerHTML =todaysDateString; document.getElementById('DateOfPurchase').value = todaysDateString; } Can someone point me in the right direction please? I have a drop down menu where people can select a month, day and year. Based on their selection, I want to show them an image. If their selection is >= July 26, 2010 but <= July 25, 2011, show the red image; If their selection is >= July 26, 2011 but <= July 25, 2012, show the white image; If their selection is >= July 26, 2012 but <= July 25, 2013, show the blue image; If their selection is >= July 26, 2013 but <= July 25, 2014, show the yellow image; I don't know how to compare a selected date to a range of dates like this. Hello, I really need your help with one. How can I use the following code below to save the date from my popup window datepicker back into a var and relay it back onto its parent page? I can't seem to figure this out: Code: <html> <head> <script> function open_cal() { var str_html = "" + "<!DOCTYPE html>\n" + "<html lang=\"en\">\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>CALENDAR</title>\n" + "<link href=\"jq/jquery-ui.css\" rel=\"stylesheet\" type=\"text/css\">\n" + "<script src=\"jq/jquery.min.js\" type=\"text/javascript\"></" + "script>\n" + "<script src=\"jq/jquery-ui.min.js\" type=\"text/javascript\"></" + "script>\n" + "<script src=\"jq/datepicker.js\" type=\"text/javascript\"></" + "script>\n" + "</head>\n" + "<body>\n" + "<div id=\"text\" style=\"font: bold 10pt Tahoma\">Enter Approval Date:</div>\n" + "<div id=\"datepicker\"></div>\n" + "</body>\n" + "</html>" var j = window.open("","CALENDAR","width=200,height=250,status=no,resizable=yes,top=200,left=200") j.opener = self; j.document.write(str_html); } </script> </head> <body> <input onclick="open_cal()" type="button" value="Open" name="B1"> </body> </html> Datepicker.js: Code: $(function() { $( "#datepicker" ).datepicker({ dateFormat: 'dd/mm/yy', onSelect: function(dateText, inst) { alert(dateText) window.close() } }) }); Any help with this is greatly and mostly appreciated. Thanks in advance, Cheers, J hello there this is in vb script. but i dont where to post it. can any one hlep me out plzz I need to check if the date entered by user is within 5th date from current date. I am trying to do it this way entered date has month and date value Code: sResvDate = 01/24 Set sMaxDays to getdate(5) but get date will give year too. and how do i compare if it less than 5th day or not. Hi folks, i am trying to generate a dynamic datefield with date mask "mm/dd/yyyy" and trying to insert it into Oracle db ...i still got the error ORA invalid month ehich means the date filed is not recognized as date: below is what i am doing : newStartDate = document.createElement( 'INPUT' ); newStartDate.setAttribute('type','Date'); newStartDate.setAttribute('id1','id'+ elementid+elementrow); newStartDate.setAttribute('name','StartDateName'+ elementid+elementrow); newStartDate.size=8; newStartDate.style.backgroundColor= bgc; any help thanks ?? Also i want to add a datepicke to this textbox..how it is posible / other option is to use Jquery datepicker but could not know how to impement it thanks again I am delving into the coding world and while I understand the basic principle of cookies, conditional statements, arrays, etc... I am still learning how to properly implement them. Any asistance with the following situation would be greatly appreciated and help with my learning as I try to reverse engineer the logic. I have looked around the web and this forum with little success. If the situation below is too complicated, I would really appreciate even a shove in the right direction regarding the logic. ----------------- How could I show a preset counter which counts up from a preset, beginning number toward a preset, end number? I imagine the increment and speed is set be the difference between the two numbers and a timeframe. Assumptions: I would rather not set the increment but edit the end number to show a steady increase. As I update that number, the increment adapts dynamically. I would want the number/script to be useful, so it should not refresh to the beginning number on each page load (i.e. num=0). When a visitor comes to the page, it must seem like the counter has been steadily been increasing in their absence. Coke or Pesi did something similar one time regarding cans sold to date (doubt it was plugged into a DB somewhere but rather based on a steady sales figure) and it was pretty cool. All the best! Hi guys, I hope to seek your help about the date function. I had the date store in my database under the type of timestamp. Now i wish to retrieve out the date store on my database and match it with today date however, I am facing problem with it. I know that I had to create a variable for it, however, after trying for many time, it still show me error. Would appreciate your kind help I acquired this from joh6nn a year ago and now need one small addtion. This code produces the next meeting date based on one's local PC date. For the days, I need ST, ND, RD, TH added. For example, instead of "August 29", I need it to kick out "August 29th". Possible!?
Code: <table border="0" cellpadding="2" cellspacing="0" width="100%" bgcolor="#EFEFEF"> <!-- BEGIN NEXT BOOSTER CLUB AND NEXT GAME NOTICES --> <tr> <td width="13" valign="top"><img border="0" src="images/dot_red_anim_13x13.gif" width="13" height="13"></td> <td valign="top"><span class="bold"><span class="red">Next Booster Club Meeting:</span></span><br> <!-- SCRIPT below automatically updates the date of the next meeting based on the PC's date --> <script> var Schedule = new Array(12); for ( var i = 0; i < 12; i++ ) { Schedule[i ] = new Array(); } var Games = new Array(12); for ( var i = 0; i < 12; i++ ) { Games[i ] = new Array(); } var weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; // Set the days you want // Because the array starts with 0, 0=January, 1=February, and so on. So, the month [7] below is one number behind the actual month number // Schedule[month-1][day] = ["first message" , "second message"]; // Schedule[7][20] = ["7:00PM" , "THIS IS THE TOPIC TEXT"]; --- see original script in another file...shows where "topic" line is added, etc. Schedule[7][19] = ["7:00pm" , ""]; // AUGUST Schedule[7][26] = ["7:00pm" , ""]; Games[7][29] = ["7:30pm", "Leander (@ Leander)"]; // Season Opener Schedule[8][2] = ["7:00pm" , ""]; // SEPTEMBER Schedule[8][9] = ["7:00pm" , ""]; Games[8][12] = ["7:30pm" , "Westwood (@ Burger Center)"]; Schedule[8][16] = ["7:00pm" , ""]; Games[8][19] = ["7:30pm" , "McNeil (@ Round Rock)"]; Schedule[8][23] = ["7:00pm" , ""]; Games[8][26] = ["7:30pm" , "Hays (@ Burger Center)"]; Schedule[8][30] = ["7:00pm" , ""]; Games[9][3] = ["7:30pm" , "S F Austin (@ House Park)"]; // OCTOBER Schedule[9][7] = ["7:00pm" , ""]; Games[9][9] = ["7:00pm" , "Westlake (@ Burger Center)"]; Schedule[9][14] = ["7:00pm" , ""]; Games[9][17] = ["7:30pm" , "Seguin (@ Seguin)"]; Schedule[9][21] = ["7:00pm" , ""]; Games[9][23] = ["7:00pm" , "Akins (@ Burger Center)"]; Schedule[9][28] = ["7:00pm" , ""]; Games[9][30] = ["7:00pm" , "San Marcos (@ Burger Center)"]; Schedule[10][4] = ["7:00pm" , ""]; // NOVEMBER Games[10][7] = ["7:30pm" , "Crockett (@ Burger Center)"]; Schedule[10][11] = ["7:00pm" , ""]; // ADD MORE MEETINGS AND-OR PLAYOFF EVENTS HERE .... WHAT YOU SEE IS FROM 2002 RIGHT NOW // Games[10][16] = ["1:00pm" , "Judson (@ Hays Stadium)"]; // Schedule[10][18] = ["7:00pm" , ""]; // Schedule[10][25] = ["7:00pm" , ""]; function dateWriter() { var today, then, start; today = new Date(); if ( Schedule[today.getMonth()][today.getDate()] ) {// only true if you explicitly set it return ("Today at " + Schedule[today.getMonth()][today.getDate()][0] + '.'); } else { for (var m = today.getMonth(); m < 12; m++) { start = ( m == today.getMonth() ) ? today.getDate() : 1; for (var d = start; d < 31; d++) { if (Schedule[m][d]) { then = new Date(today.getFullYear(), m, d); return (weekdays[then.getDay()] + ", " + months[m] + " " + d + " @ " + Schedule[m][d][0]); } } } } } function dateWriter2() { var today, then, start; today = new Date(); if ( Games[today.getMonth()][today.getDate()] ) {// only true if you explicitly set it return ("Today at " + Games[today.getMonth()][today.getDate()][0] + ' vs ' + Games[today.getMonth()][today.getDate()][1]+'.'); } else { for (var m = today.getMonth(); m < 12; m++) { start = ( m == today.getMonth() ) ? today.getDate() : 1; for (var d = start; d < 31; d++) { if (Games[m][d]) { then = new Date(today.getFullYear(), m, d); return (weekdays[then.getDay()] + ", " + months[m] + " " + d + " @ " + Games[m][d][0] + "<br>" + " vs " + Games[m][d][1]); } } } } } document.writeln("<span class='bold'>" + dateWriter() + " in the cafeteria.</span><br>All football parents are highly encouraged to attend!"); document.writeln("<br><img src='images/1x1.gif' width='1' height='5' border='0'></td></tr>"); document.writeln("<tr><td width='13' valign='top'><img border='0' src='images/dot_red_anim_13x13.gif' width='13' height='13'></td><td valign='top'><span class='bold'><span class='red'>Next Game (<a href='schedule_v.htm'><span class='bold'>details</span></a>):</span></span></span><br><span class='bold'>" + dateWriter2() + "</span><br><img src='images/1x1.gif' width='1' height='5' border='0'></td></tr>"); // document.writeln(dateWriter2()); </script> </td> </tr> </table> hi friends, i have one textbox(txtdate) ,if user enters into the textbox automatically it has to format (dd/mm/yyyy). how to do. for your reference i have vbscript code but i don't know how to convert. can u please tell me . vbscript code: Hi all, I have vbscript code to validate date.can u please tell me how to convert it to javascript. Code: <script language='vbscript'> <!-- Function formatDate() Dim sMonth Dim sDay Dim sYear Dim sDate Dim vDate Dim sDateValue Dim dateformat Dim regEx Dim bTest Dim scMonth Dim scYear Dim vYear On error resume next formatDate=True sCurrDay = Right("0" & Cstr(Day(Now())),2) sCurrYear = Cstr(Year(Now())) sDateValue = window.event.srcElement.value if (len(sDateValue)=0) Then Exit Function Select Case len(sDateValue) Case 1: If (sDateValue="0") Then sDateValue = "1" End If sDateValue = "0" & sDateValue & "/" & sCurrDay & "/" & sCurrYear Case 2: sDateValue = sDateValue & "/" & sCurrDay & "/" & sCurrYear Case 3: sDateValue = sDateValue & sCurrDay & "/" & sCurrYear Case 4: sDateValue = Mid(sDateValue,1,3) & "0" & Mid(sDateValue,4,1) & "/" & sCurrYear Case 5: sDateValue = sDateValue & "/" & sCurrYear Case 6: sDateValue = sDateValue & sCurrYear Case 7: if (Mid(sDateValue,7,1)="1") then sDateValue = Mid(sDateValue,1,7) & "9" Else sDateValue = Mid(sDateValue,1,7) & "0" End If Case 8: window.event.srcElement.value = sDateValue Case 9: sDateValue=mid(sDateValue,1,6) & mid(sdateValue,8,2) Case Else If (len(sDateValue)<>10 and len(sDateValue)<>8) Then window.event.cancelBubble=true window.event.returnValue = false window.event.srcElement.setAttribute "valid","false" alert "Invalid Date, must enter 8 or 10 characters!" window.event.cancelBubble=true Window.event.returnValue = False window.event.srcElement.focus() window.event.srcElement.select() window.event.cancelBubble=true Window.event.returnValue = False formatDate=False On Error Goto 0 Exit Function End If End Select If (instr(1,sDateValue,"/") or instr(1,sDateValue,"-")) Then sDate=sDateValue Else sMonth = Mid(sDateValue,1,2) sDay = Mid(sDateValue,3,2) sYear = Mid(sDateValue,5,4) sDate = translateDate(sMonth,sDay,sYear) End If sMonth = Mid(sDateValue, 1, 2) If (CLng(sMonth) > 12 Or CLng(sMonth) < 0) Then window.event.cancelBubble=true Window.event.returnValue = False window.event.srcElement.setAttribute "valid","false" alert "Invalid Month!" window.event.cancelBubble=true Window.event.returnValue = False Window.event.srcElement.focus() window.event.srcElement.select() window.event.cancelBubble=true Window.event.returnValue = False formatDate=False Exit Function End If on error resume next vDate = CDate(sDate) If (Err.number <> 0) Then window.event.cancelBubble=true window.event.returnValue = false window.event.srcElement.setAttribute "valid","false" alert "Invalid Date!" window.event.cancelBubble=true Window.event.returnValue = False window.event.srcElement.focus() window.event.srcElement.select() window.event.cancelBubble=true Window.event.returnValue = False formatDate=False Else vYear=Year(vDate) If (vYear<1980) Then window.event.cancelBubble=true window.event.returnValue = false window.event.srcElement.setAttribute "valid","false" alert "The date must be greater than 1979!" window.event.cancelBubble=true Window.event.returnValue = False window.event.srcElement.focus() window.event.srcElement.select() window.event.cancelBubble=true Window.event.returnValue = False formatDate=False Else window.event.srcElement.value = sDate window.event.srcElement.setAttribute "valid","true" window.event.returnValue=true End If End If On Error Goto 0 End Function //--> </script> Regards I have found many examples for checking CC exp year and month, but none that do this type of format. I know Js doesn't have a native explode function or anything of the sort so I don't know where to even begin. I have already checked if the field is empty, now what I need to do is validate the expiration date, the date is in format "MM/YY". Any ideas? Hi, i need to get the current date into some format so that it doesn't change? here i have some code: Code: function printTime(){ var d=new Date(); var utc = d.toUTCString(); alert(utc); } for example this show for me: Mon, 26 Dec 2011 21:55:43 GMT I would like to get this information again, lets say 5 minutes later - but i want the information to still read Mon, 26 Dec 2011 21:55:43 GMT not Mon, 26 Dec 2011 22:00:43 GMT for example Any help greatly appreciated Hello, and thanks for a great forum I have downloaded a script called Display time of last visit. Since I live in Norway, so the date is on the wrong line. It's November 18, but I want the date to be before the month if ya know what I mean. Is there anyone out there who can be so kind and help me change the script so that it is correct? I've tried, but ..... this is what it says now: Thursday, November 18, 2010 09:59:28 AM I want it to be (is it is possibe to remove AM ?) Thursday, 18, November 2010 09:59:28 AM Sincerely, from Norway Jon isprinsessa.com Hi, Got input boxes for begin and end dates - using JQuery for date picker calendar for each. Need to validate 2 things - 1 is that end date is => than begin date, 2 is that user enters date into begin date rather than just numbers. I got date picker JQuery from another office where I work and can not change their parameters or code. So my input boxes allow for date picker selection or manual data entry. The end date input box can be empty if user only inputting one day for begin date and not a range. Also have 3 more begin/end date input box sets which are not visible until user clicks "Add Row" button - one click, one set added. Want to insure if user added row and input date then removed row (clicked "Remove Row" button) that the data entered is removed and not inserted into database. Add & remove rows: Code: <script type="text/javascript"> var showing = 0; function showAnother() { if ( showing <= 3 ) { ++showing; document.getElementById("row"+showing).style.display =""; } if ( showing == 3) { alert("Maximum number of rows allowed."); } } </script> <script type="text/javascript"> function removeRow() { if ( showing >= 0 ) { document.getElementById("row"+showing).style.display ="none"; showing--; } if ( showing == 0 ) { return true; } } </script> Begin & end date input boxes: Code: <td><input style="width: 70px" type="text" id="startdate1" name="startdate1" /></td> <td><input name="stopdate1" style="width: 70px" type="text" id="stopdate1"/></td> Other 3 begin & end date input boxes same with names increased by one digit - startdate2/stopdate2, and so on to 4. Thanks, John HI Guys, Could someone help me out; i am checking if return_date is greater than the departure_date. Somehow the date is checking on mm/dd/yyyy format while my form is capturing date on dd/mm/yyyy format. Can someone point out where i can actually change this format. I would like to stick to dd/mm/yyyy format. Here is my code:- <script language="javascript" type="text/javascript"> function doDateCheck() { var depart=new Date(document.getElementById('DPC_date1').value); var return=new Date(document.getElementById('DPC_date2').value); if(eval(return.getTime() )<eval(depart.getTime())) { alert("Return date must be greater then departure date."); return false; } return true; } </script> I can't wrap my head around this at the moment so with the hope of finding someone willing to take a stab I am posting this to all of you. I need to create a savings ticker that shows $ saved per second. The data is as follows then = date script is created now = current date std = savings to date in $ avg = average savings per second in $ It would need to calculate the difference in time between then and now, convert that to an integer that can then be multiplied by avg then std would be added. thanks in advance |