JavaScript - Date Intervals
Hello,
i have a qustion that maybe has a very simple answer but i'm a beginner in working with scripts and i couldn't find it. i have the code below. so i have 5 time intervals but the thing that i couldn't do is to make that for saturdays to show only the 5th interval and hide the other ones. The full code is attached. Thank you! Code: <script type="text/javascript" src="/js/date.js"></script> <!--[if IE]><script type="text/javascript" src="/js/jquery.bgiframe.min.js"></script><![endif]--> <script type="text/javascript" src="/js/jquery.datePicker.js"></script> <link rel="stylesheet" type="text/css" media="screen" href="/js/datePicker.css"> <br/> <div id="livraredata" > <#if cache.getSessionInterface(jsp_request).getAttribute("ro.kubu.magazin.EditareComanda")?exists> <br/>Detalii de livra <input type="text" id="livraredetalii" name="livraredetalii" value="${c_livrare_detalii}"/> <#else> <b>Data livra </b><input id="livare-data" type="text" class="date-picker" style="width:100px;"/> <b>Interval orar: </b> <select id="livare-interval" style="width:100px !important;"> <option value="09-13" id="li1">09-13</option> <option value="13-17" id="li2">13-17</option> <option value="17-21" id="li3">17-21</option> <option value="09-21" id="li4">09-21</option> <option value="10-17" id="li5">10-17</option> </select> <input type="hidden" id="livraredetalii" name="livraredetalii" value="${c_livrare_detalii}"/> <script type="text/javascript">//<![CDATA[ var today = new Date(); var firstday = today; <#if sel?exists> var zonaclasa = ${sel.getClasa()}; <#else> var zonaclasa = -1; </#if> function updateinterval_livraredetalii() { var dd = $('#livare-data').val(); dd = Date.fromString(dd); dd = dd.asStringFmt('yyyy-mm-dd'); $('#livraredetalii').val(dd+" "+$('#livare-interval').val()); } function update_livraredetalii() { var dd = $('#livare-data').val(); dd = Date.fromString(dd); var oraazi = new Date().getHours();//0--23 var ziazi = new Date().getDay();//0--6, 0 dum if (dd.getDayOfYear() == today.getDayOfYear() && ziazi != 6 && oraazi >=12) { $('#li1').hide();$('#li4').hide();$('#li5').hide(); $('#li2').show(); $('#li3').show(); $('#livare-interval').val($('#li2').html()); } else if (dd.getDayOfYear() == today.getDayOfYear() && ziazi == 6) { $('#li1').hide(); $('#li2').hide(); $('#li3').hide(); $('#li4').hide(); $('#livare-interval').val($('#li5').html()); } else { $('#li1').show(); $('#li2').show(); $('#li3').show(); $('#li4').show(); $('#li5').hide(); } dd = dd.asStringFmt('yyyy-mm-dd'); $('#livraredetalii').val(dd+" "+$('#livare-interval').val()); } $(function(){ today = new Date();today.setHours(0);today.setMinutes(0);today.setSeconds(0);today.setMilliseconds(0); var oraazi = new Date().getHours();//0--23 var ziazi = new Date().getDay();//0--6, 0 dum var msecsInADay = 86400000; firstday = today; if (ziazi == 0 || (ziazi != 6 && oraazi >= 16) ) { //daca e duminica sau e zi a saptamanii dupa ora 16 firstday = new Date(today.getTime()+msecsInADay); } else if (ziazi == 6 && oraazi >= 10) {//daca e sambata dupa 10 firstday = new Date(today.getTime()+2*msecsInADay); //urmatoare zi e luni } else if (zonaclasa != 0) { firstday = new Date(today.getTime()+msecsInADay);$('#li4').hide(); } else if (zonaclasa != 0 && oraazi >= 17) { firstday = new Date(today.getTime()+2*msecsInADay); } else if (oraazi >= 9) { //daca e dupa ora 9 dispar intervalele 1 si 4 $('#li1').hide();$('#li4').hide(); $('#li2').show();$('#li3').show(); } <#if mag.hasText("setup.inchideazi")> firstday = new Date(today.getTime()+msecsInADay); </#if> <#if mag.hasText("setup.inchidemaine")> firstday = new Date(today.getTime()+2*msecsInADay); </#if> Date.format = 'dd-mmm-yyyy'; $('.date-picker').datePicker({ clickInput:true, showYearNavigation:false, createButton:false, renderCallback:function($td,thisDate,month,year) { if (thisDate.getDay() == 0 || thisDate.getDayOfYear() < firstday.getDayOfYear()) { //ascundem default toate zilele pana la firstday si duminicile $td.addClass('disabled'); } } }).val(firstday.asString()) .trigger('change'); //$('.date-picker').datePicker({startDate:'01/01/2000',showYearNavigation:'true'}); $('#livare-interval').change(function(){ updateinterval_livraredetalii(); }); $('#livare-data').change(function(){ update_livraredetalii(); }); update_livraredetalii(); }); //]]></script> </#if> </div><br/> Similar TutorialsI have an interval set that runs indefinitely (backgrounds switching) or until the viewer stops it. I've noticed that when I close a tab while it's running and revisit the page, it "doubles" the interval and the backgrounds get mixed up. Refreshing the page returns it to normal. Does anyone know how to fix this? I've tried clearing the interval with window.onunload and window.onbeforeunload. I'm thinking it has something to do with firefox not clearing its cache for the tab. I'll look into disabling that. Hi all. I am having a problem understanding exactly how setInterval and setTimeout work and really need some help. I want to create an array and then print out each element one at a time at one second intervals. I've only been able to come up with something like this, but it just prints the last value of the array after a second. Code: <script type = "text/javascript"> <!-- var myArray = new Array(); for (var i = 0; i < 11; i++){ myArray[i]=i+50; } for (var i = 0; i < myArray.length-1; i++){ setInterval("document.getElementById('here').innerHTML = myArray[i];", 1000); } //--> </script> <div id="here">Stuff here</div> i know there are pre-made scripts to do what i'm doing. i want to create this myself to learn. i'm trying to create a list of section titles with arrows next to them, clicking on an arrow expands the section to read it's text, clicking on the arrow again collapses the section text. additionally, i would like an "expand all" and "collapse all" link and that's where my issue baffles me. my js - Code: function expandAll() { var collapsedDivs = document.getElementsByClassName('collapsed'); for (var i=0; i<collapsedDivs.length; i++) { var expandMe = collapsedDivs[i]; expandMe.style.display = 'block'; expandMe.addClassName('expanded'); expandMe.removeClassName('collapsed'); document.getElementById('arrow_'+i).innerHTML = '<img src="../media/hide.gif" />'; } } my html - Code: <div style="float:left" id="arrow_0"><img src="../media/show.gif" /></div><div style="margin-left:20px; text-align:left; font-weight:bolder; font-size:14px">SECTION ONE TITLE</div> <div class="collapsed" style="margin-left:20px; margin-right:30px; text-align:left; display:none">Section one text text text text text text text text text text text text text text text text text text text text text text </div> <div style="float:left" id="arrow_1"><img src="../media/show.gif" /></div><div style="margin-left:20px; text-align:left; font-weight:bolder; font-size:14px">SECTION TWO TITLE</div> <div class="collapsed" style="margin-left:20px; margin-right:30px; text-align:left; display:none">Section two text text text text text text text text text text text text text text text text text text text text text text </div> <div style="float:left" id="arrow_2"><img src="../media/show.gif" /></div><div style="margin-left:20px; text-align:left; font-weight:bolder; font-size:14px">SECTION THREE TITLE</div> <div class="collapsed" style="margin-left:20px; margin-right:30px; text-align:left; display:none">Section three text text text text text text text text text text text text text text text text text text text text text text </div> <div style="float:left" id="arrow_3"><img src="../media/show.gif" /></div><div style="margin-left:20px; text-align:left; font-weight:bolder; font-size:14px">SECTION FOUR TITLE</div> <div class="collapsed" style="margin-left:20px; margin-right:30px; text-align:left; display:none">Section four text text text text text text text text text text text text text text text text text text text text text text </div> upon executing the function, the result is the text for sections one and three being expanded and the arrows for one and two being changed. why? what am i doing wrong? I've found many examples of creating slideshows using javascript all over the internet and these forums. However, I haven't found any that show how to create a slideshow and give each slide a different time interval between switching to the next one. I'm changing my website over from a Flash based one to something that can be read on all devices. In doing so I've looked for ways to add a little motion to the site. I'm working with a friend who has been doing most of the site but here and there I like to get my hands dirty and try some things on my own. Unfortunately he doesn't know Javascript. I wanted to have an animation window in the bottom corner of the page. Look at http://www.whyreboot.com/blog to see what I came up with. I took a slider plugin for Wordpress and basically created a bunch of slides and entered them in to switch every .5s so that I could change how quickly they changed images by making some of them repeat the same slide 4 times for 2s, 2 times for 1s, etc. Though it's not pretty, it works. On Firefox everything looks great although it'd be nice to have fade in and out on each slide. On an iPad or IE it actually shows the flash between slides even when they're the same image. Quite frankly, it's ugly. Does anybody have any ideas? Please keep in mind that I am a network systems engineer by trade so the only coding I know is Cisco IOS, etc. I'm trying to get this to work in a Wordpress site on a window with dimensions of 450X230. I apologize if this is not the correct place to look for help on this. I have read the forum fules and guidelines and this seemed to be the right place. Thanks ahead of time for any sage advice from what looks like a great community of web geeks! Hey guys, I am new at JavaScript, but I have been able to piece together some code for a stopwatch. I have everything the way I want it in regards to the function and look of the stopwatch, but I want to be able to set timers so that the ss() function in the code below will go and stop automatically at intervals I can set. I just can't seem to get there with this one and any help is greatly appreciated. Thank you for your time. Code: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Test</title> <script type="text/javascript"> var t=[0, 0, 0, 0, 0, 0, 0, 1]; document.onkeyup=function(event) { if((event.which && event.which === 32) || (event.keyCode && event.keyCode === 32)) { ss() } } function ss() { t[t[2]]=(new Date()).valueOf(); t[2]=1-t[2]; if (0==t[2]) { clearInterval(t[4]); t[3]+=t[1]-t[0]; t[4]=t[1]=t[0]=0; disp(); } else { t[4]=setInterval(disp, 43); } } function r() { if (t[2]) ss(); t[4]=t[3]=t[2]=t[1]=t[0]=0; disp(); t[7]=1; } function disp() { if (t[2]) t[1]=(new Date()).valueOf(); t[6].value=format(t[3]+t[1]-t[0]); } function format(ms) { var d=new Date(ms+t[5]).toString() .replace(/.*([0-9][0-9]:[0-9][0-9]:[0-9][0-9]).*/, '$1'); var x=String(ms%1000); while (x.length<3) x='0'+x; d+='.'+x; return d; } function load() { t[5]=new Date(1970, 1, 1, 0, 0, 0, 0).valueOf(); t[6]=document.getElementById("disp"); disp(); } </script> </head> <body onload='load();'> <div></div> <input type="text" style="border: none" id="disp" readonly /> <style type="text/css"> #disp { font-size: 180px; text-align: center; font-family: Verdana; } </style> </body> <form> </form> </html> 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 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? 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 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. 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! 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> 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 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 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 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 |