Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Mel Smith" Newsgroups: comp.lang.javascript Subject: Re: Date Conversion ? Date: Fri, 20 Dec 2013 09:52:57 -0700 Lines: 116 Message-ID: References: X-Trace: individual.net 9CkIsof+XpS2kBZy28gHSQcYeQgo0l0cCGuFuCYqVJX9liy6+G Cancel-Lock: sha1:CiRJpef0fqo722coB1dn9+VUkJM= X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-RFC2646: Format=Flowed; Original Xref: csiph.com comp.lang.javascript:22370 Dr. J said: > Show us your code, and we can think about whether they are reliably > solved. Hi Dr Stockton: Here's my latest iteration of my date checking function (which includes JJ's parsedate() function and Thomas' Math function usage to find lows and highs. -Mel Smith ********************************* function chkdate(stnd,cdate) { // where stnd is either "ST" or "ND" and // where cdate is in the form: mm-dd-yyyy or mm/dd/yyyy (read/write) // global scrcols is currently 13 // global playdatecol is currently the third column (i.e., 2) var lok = true ; var i,j,scrtable,rows,cells,cell,numrows; var playdatestr,playdateval ; var datearray = [] ; var low,high,nlen ; var yr,mth,day ; // generalized checking for a modified date var lowdate,nlowyr,clowyr,nlowmth,clowmth,nlowday,clowday ; var highdate,nhighyr,chighyr,nhighmth,chighmth,nhighday,chighday ; if (partof("mm",cdate) && partof("dd",cdate) ) { // then no date was entered -- so start searching scrtable = getobj("iscrtable") ; rows = scrtable.rows ; numrows = rows.length ; for (i=4;i 12) return !lok ; day = +cdate.substr(3,2) ; if (day < 1 || day > 31) return !lok ; // the above is not a complete check -- do better later yr = +cdate.substr(6,4) ; // today is a global date object of current day if (yr < 2000 || yr > today.getFullYear()) return !lok ; // now check presence of separators and allow '/' or '-' if (!partof(cdate.substr(2,1),"/-")) return !lok ; if (!partof(cdate.substr(5,1),"/-")) return !lok ; return lok ; } function parseDate(dateStr) { // by JJ of JS/ES group // for "Mmm dd/yy" format, year 20nn only. // converts to "Mmm dd yyyy" (good for FF, IE8, Chrome, Opera). // returns NaN if dateStr is in invalid format. var date = dateStr.replace(/([a-z]+ \d+)\/(\d+)/,"$1 20$2"); return (new Date(date)).valueOf(); }