JavaScript - Vb Script Check A Date Is Less Than Another Date.
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. Similar TutorialsHi to all, I need some help checking a date field with javascript, I need to veryfy that the date introduced is not previous from today so when the submit button is clicked an alert comes up: "Date can't be previous from today" the date is compared with a PHP variable with de date from server "$todays_date" in 31/12/2011 format. Code: if (frm.date.value [is previous from] $todays_date) { alert('Date can't be previous from today') frm.date.focus() return false } Any help?? Thanks 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. 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 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? 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 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. I have the following code on my site. I use this in the header of mysite Code: <script type="text/javascript"> var weekdaystxt=["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"] var montharray=("January","February","March","April","May","June","July","August","September","October","November","December") function showLocalgetthedate(){ var mydate=new Date() var year=mydate.getYear() if (year < 1000) year+=1900 var day=mydate.getDay() var month=mydate.getMonth() var daym=mydate.getDate() if (daym<10) daym="0"+daym function showLocalTime(container, servermode, offsetMinutes, displayversion){ if (!document.getElementById || !document.getElementById(container)) return this.container=document.getElementById(container) this.displayversion=displayversion var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>' this.localtime=this.serverdate=new Date(servertimestring) this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time this.updateTime() this.updateContainer() } showLocalTime.prototype.updateTime=function(){ var thisobj=this this.localtime.setSeconds(this.localtime.getSeconds()+1) setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second } showLocalTime.prototype.updateContainer=function(){ var thisobj=this if (this.displayversion=="long") this.container.innerHTML=this.localtime.toLocaleString() else{ var hour=this.localtime.getHours() var minutes=this.localtime.getMinutes() var seconds=this.localtime.getSeconds() var ampm=(hour>=12)? "PM" : "AM" var dayofweek=weekdaystxt[this.localtime.getDay()] this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+ " "+montharray(month)+" ("+dayofweek+")" } setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second } function formatField(num, isHour){ </script> I use this to display the information. Code: <script type="text/javascript"> new showLocalTime("timecontainer", "server-php", 0, "short") new showLocalTime("timecontainer2", "server-php", +300, "short") new showLocalTime("timecontainer3", "server-php", +360, "short") new showLocalTime("timecontainer4", "server-php", +600, "short") </script> This gives me 4 clocks which i set at different time zones Can someone assist me in showing me a way to accelerate the time for this clock. I would like the minutes to be only 5 seconds long versus the normal 60 seconds per minute. I fly a flight sim and the in game world clock is accelerated at this pace and my squad would like to be able to see the time it would currently be in the game so we can avoid launching the game at certain in game times. If this can't be done, does anyone know of a separate java script that can accomplish this? Thank you in advance, any and all help would be greatly appreciated. Quote: <SCRIPT LANGUAGE="JavaScript1.2"> <!-- Begin var days=new Array(8); days[1]="Monday"; days[2]="Tuesday"; days[3]="Wednesday"; days[4]="Thursday"; days[5]="Friday"; days[6]="Saturday"; days[7]="Sunday"; var months=new Array(13); months[1]="January"; months[2]="February"; months[3]="March"; months[4]="April"; months[5]="May"; months[6]="June"; months[7]="July"; months[8]="August"; months[9]="September"; months[10]="October"; months[11]="November"; months[12]="December"; var time=new Date(); var lmonth=months[time.getMonth() + 1]; var ldays=days[time.getDay() + 1]; var date=time.getDate(); var year=time.getYear(); var hour=time.getHours(); var min=time.getMinutes() if (year < 2000) year = year + 1900; if (hour > 15) { date = date + 1; } document.write("<center>" + lmonth +" "); document.write(date + ", " + year + "</center>"); // End --> </SCRIPT> </CENTER> Can anyone help me edit this so that on Saturday at 10am the date displays mondays date. Thanks Could someone edit this script so the date is always 2 weeks infront of the actual date? <script language="JavaScript"> <!-- var now = new Date(); var days = new Array( 'Sunday','Monday','Tuesday', 'Wednesday','Thursday','Friday','Saturday'); var months = new Array( 'January','February','March','April','May', 'June','July','August','September','October', 'November','December'); var date = ((now.getDate()<10) ? "0" : "")+ now.getDate(); function fourdigits(number) { return (number < 1000) ? number + 1900 : number;} today = days[now.getDay()] + ", " + months[now.getMonth()] + " " + date + ", " + (fourdigits(now.getYear())); document.write(today); //--> </script> Thanks Hello everyone, I have a date script, but I want it to be adjusted so for example today it's September 17th 2009, but I want it to say September 15th 2009, so it removes automaticly 2 days.. I tried allot of things but I am not a javascript expert, I hope someone can help me out! Code: <script language="JavaScript" type="text/javascript"> <!-- var month = new Array(); month[0]="January"; month[1]="February"; month[2]="March"; month[3]="April"; month[4]="May"; month[5]="June"; month[6]="July"; month[7]="August"; month[8]="September"; month[9]="October"; month[10]="November"; month[11]="December"; var day = new Array(); day[0]="Sunday"; day[1]="Monday"; day[2]="Tuesday"; day[3]="Wednesday"; day[4]="Thursday"; day[5]="Friday"; day[6]="Saturday"; today = new Date(); date = today.getDate(); day = (day[today.getDay()]); month = (month[today.getMonth()]); year = (today.getFullYear()); suffix = (date==1 || date==21 || date==31) ? "st" : "th" && (date==2 || date==22) ? "nd" : "th" && (date==3 || date==23) ? "rd" : "th" function print_date() { document.write(day + "," + " " + date + "<sup>" + suffix + "</sup>" + " " + month + "," + " " + year); } // --> </script> <script> <!-- print_date(); //--> </script> What I am looking to do is auto-populate a number of forms based on what a user chooses as a starting date. For example: If a user enters 12/12/2009 I want the other fields to automatically populate with the next 2 weeks (12/13/2009, 12/14/2009, 12/15/2009 etc.) Anyone have a useful script that I can use given that these fields are formatted as dates? The idea is to save time by only having to fill in the first date in the timesheet. HI all, maybe someone can help me. I am using this script: http://www.javascriptkit.com/script/...selector.shtml on my site but as of Feb 1st 2012 the day of the week and the date do not match anymore. Feb 1st 2012 is not a thursday. Try example on site (link) to see what I mean. Can anyone help me debug this? Any help greatly appreciated Dennis 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 have been using the following script for some time and it has only just been made known to me that it fails on todays date ! not sure if this is the case for other days but the days of the week are all messed up and do not show correctly for a date in June 2011. Code: var ds_i_date = new Date(); ds_c_month = ds_i_date.getMonth() + 1; ds_c_year = ds_i_date.getFullYear(); // Get Element By Id function ds_getel(id) { return document.getElementById(id); } // Get the left and the top of the element. function ds_getleft(el) { var tmp = el.offsetLeft; el = el.offsetParent while(el) { tmp += el.offsetLeft; el = el.offsetParent; } return tmp; } function ds_gettop(el) { var tmp = el.offsetTop; el = el.offsetParent while(el) { tmp += el.offsetTop; el = el.offsetParent; } return tmp; } // Output Element var ds_oe = ds_getel('ds_calclass'); // Container var ds_ce = ds_getel('ds_conclass'); // Output Buffering var ds_ob = ''; function ds_ob_clean() { ds_ob = ''; } function ds_ob_flush() { ds_oe.innerHTML = ds_ob; ds_ob_clean(); } function ds_echo(t) { ds_ob += t; } var ds_element; // Text Element... var ds_monthnames = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; // You can translate it for your language. var ds_daynames = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ]; // You can translate it for your language. // Calendar template function ds_template_main_above(t) { return '<table cellpadding="3" cellspacing="1" class="ds_tbl">' + '<tr>' + '<td class="ds_head" style="cursor: pointer" onclick="ds_py();"><<</td>' + '<td class="ds_head" style="cursor: pointer" onclick="ds_pm();"><</td>' + '<td class="ds_head" style="cursor: pointer" onclick="ds_hi();" colspan="3">[Close]</td>' + '<td class="ds_head" style="cursor: pointer" onclick="ds_nm();">></td>' + '<td class="ds_head" style="cursor: pointer" onclick="ds_ny();">>></td>' + '</tr>' + '<tr>' + '<td colspan="7" class="ds_head">' + t + '</td>' + '</tr>' + '<tr>'; } function ds_template_day_row(t) { return '<td class="ds_subhead">' + t + '</td>'; // Define width in CSS, XHTML 1.0 Strict doesn't have width property for it. } function ds_template_new_week() { return '</tr><tr>'; } function ds_template_blank_cell(colspan) { return '<td colspan="' + colspan + '"></td>' } function ds_template_day(d, m, y) { return '<td class="ds_cell" onMouseout="this.style.background=\'#EEE\';" onMouseover="this.style.background=\'#999\';" onclick="ds_onclick(' + d + ',' + m + ',' + y + ')">' + d + '</td>'; // Define width the day row. } function ds_template_main_below() { return '</tr>' + '</table>'; } // This one draws calendar... function ds_draw_calendar(m, y) { // First clean the output buffer. ds_ob_clean(); // Here we go, do the header ds_echo (ds_template_main_above(ds_monthnames[m - 1] + ' ' + y)); for (i = 0; i < 7; i ++) { ds_echo (ds_template_day_row(ds_daynames[i])); } // Make a date object. var ds_dc_date = new Date(); ds_dc_date.setMonth(m - 1); ds_dc_date.setFullYear(y); ds_dc_date.setDate(1); if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) { days = 31; } else if (m == 4 || m == 6 || m == 9 || m == 11) { days = 30; } else { days = (y % 4 == 0) ? 29 : 28; } var first_day = ds_dc_date.getDay(); var first_loop = 1; // Start the first week ds_echo (ds_template_new_week()); // If sunday is not the first day of the month, make a blank cell... if (first_day != 0) { ds_echo (ds_template_blank_cell(first_day)); } var j = first_day; for (i = 0; i < days; i ++) { // Today is sunday, make a new week. // If this sunday is the first day of the month, // we've made a new row for you already. if (j == 0 && !first_loop) { // New week!! ds_echo (ds_template_new_week()); } // Make a row of that day! ds_echo (ds_template_day(i + 1, m, y)); // This is not first loop anymore... first_loop = 0; // What is the next day? j ++; j %= 7; } // Do the footer ds_echo (ds_template_main_below()); // And let's display.. ds_ob_flush(); // Scroll it into view. //ds_ce.scrollIntoView(); } // A function to show the calendar. // When user click on the date, it will set the content of t. function ds_sh(t) { // Set the element to set... ds_element = t; // Make a new date, and set the current month and year. var ds_sh_date = new Date(); ds_c_month = ds_sh_date.getMonth() + 1; ds_c_year = ds_sh_date.getFullYear(); // Draw the calendar ds_draw_calendar(ds_c_month, ds_c_year); // To change the position properly, we must show it first. ds_ce.style.display = ''; // Move the calendar container! the_left = ds_getleft(t); the_top = ds_gettop(t) + t.offsetHeight; ds_ce.style.left = the_left + 'px'; ds_ce.style.top = the_top + 'px'; // Scroll it into view. //ds_ce.scrollIntoView(); } // Hide the calendar. function ds_hi() { ds_ce.style.display = 'none'; } // Moves to the next month... function ds_nm() { // Increase the current month. ds_c_month ++; // We have passed December, let's go to the next year. // Increase the current year, and set the current month to January. if (ds_c_month > 12) { ds_c_month = 1; ds_c_year++; } // Redraw the calendar. ds_draw_calendar(ds_c_month, ds_c_year); } // Moves to the previous month... function ds_pm() { ds_c_month = ds_c_month - 1; // Can't use dash-dash here, it will make the page invalid. // We have passed January, let's go back to the previous year. // Decrease the current year, and set the current month to December. if (ds_c_month < 1) { ds_c_month = 12; ds_c_year = ds_c_year - 1; // Can't use dash-dash here, it will make the page invalid. } // Redraw the calendar. ds_draw_calendar(ds_c_month, ds_c_year); } // Moves to the next year... function ds_ny() { // Increase the current year. ds_c_year++; // Redraw the calendar. ds_draw_calendar(ds_c_month, ds_c_year); } // Moves to the previous year... function ds_py() { // Decrease the current year. ds_c_year = ds_c_year - 1; // Can't use dash-dash here, it will make the page invalid. // Redraw the calendar. ds_draw_calendar(ds_c_month, ds_c_year); } // Format the date to output. function ds_format_date(d, m, y) { // 2 digits month. m2 = '00' + m; m2 = m2.substr(m2.length - 2); // 2 digits day. d2 = '00' + d; d2 = d2.substr(d2.length - 2); // YYYY-MM-DD return d2 + '-' + m2 + '-' + y; } // When the user clicks the day. function ds_onclick(d, m, y) { // Hide the calendar. ds_hi(); // Set the value of it, if we can. if (typeof(ds_element.value) != 'undefined') { ds_element.value = ds_format_date(d, m, y); // this part is a personal bit of code to allow my page to update correctly and in time. if("fireEvent" in ds_element) ds_element.fireEvent("onChange"); else { var evt = document.createEvent("HTMLEvents"); evt.initEvent("change", false, true); ds_element.dispatchEvent(evt); } // // Maybe we want to set the HTML in it. } else if (typeof(ds_element.innerHTML) != 'undefined') { ds_element.innerHTML = ds_format_date(d, m, y); // I don't know how should we display it, just alert it to user. } else { alert (ds_format_date(d, m, y)); } } Hi Script Experts I am facing issue in below code for Brisilia time zone.(GMT-3). Issue comes in October month only. It is going tobig loop. I am not getting how Date object is behaving here. Thanks in advance Pranav Sharma *********************************** <script type="text/javascript"> var nDate; var nCurrentYear = 2011; var nCurrentMonth = 10; nYear=2011; nMonth=10; var date = new Date(nYear, nMonth-1, 1); document.write('Month:'+date.getMonth() +':CurrentMonth:'+nCurrentMonth); while (date.getMonth() == nCurrentMonth-1) { nDate = date.getDate(); document.write(date.toDateString()); date = new Date(nCurrentYear, date.getMonth(), date.getDate()+1); } </script> ********************************** 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 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 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, 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 |