Re: Universal Web Connect and DATE fields
Posted in 1998
Here is one in JavaScript: Eduardo Quint's wrote in message <6rhech$ecn$1@salico.udc.es>... >Hi, > >When we retrieve date fields from a <?MISQL> tag, Universal Web Connect >expands it to dd/mm/yy format in html document. >We need display dd/mm/yyyy format. > >Does anyone know any variable/function ... to solve it ? > > Here is a JavaScript function that formats a date on the client side. <input type=text name="SomeDate" size=8 maxlength=15 onBlur="this.value=MakeDate(this.value,'MDY');"> <script language="JavaScript"> <!--// function MakeDate(str,fmt) { var i = new Array(3); var curr = 0; var brk, ch, y, m, d; i[0] = i[1] = i[2] = ""; if(str == "" || str == "0"){return "";} if(str.substring(0,1) == " ") { alert("Please remove leading spaces"); return str; } for (x = 0; x < str.length; x++) { ch = str.substring(x,x + 1) if (!isNaN(parseInt(ch))) { brk = 0; if (i[curr]) { i[curr] += ch; }else { i[curr] = ch; } } else { if (!brk) { curr++; brk++; } } } if (curr != 2 || brk == 1) alert("Please re-format date"); return "0"; } m = 0; d = 1; y = 2; if(fmt == "YMD") { y = 0; m = 1; d = 2; } if(fmt == "DMY") { d = 0; m = 1; y = 2; } if (i[d].length == 1 && parseInt(i[d]) < 10) { i[d] = "0" + i[d]; } if (i[m].length == 1 && parseInt(i[m]) < 10) { i[m] = "0" + i[m]; } if (i[y].length == 1 && parseInt(i[y]) < 10) { i[y] = "0" + i[y]; } if (i[y].length == 2 ) { if (parseInt(i[y]) > 70) { i[y] = 1900 + parseInt(i[y]); } else { i[y] = 2000 + parseInt(i[y]); } } return i[m] + "/" + i[d] + "/" + i[y]; } //--> </script> You can also write a routine (on the server) that converts the date into a julian date (integer) and use that. Good Luck.