I am trying to convert a querystring value into Javascript date object and then converting it into ISO Date format.
I have three button - one extracts the querystring and displays the value - works properly Second, uses first function to extract querystring (works) and then converts to Date - fails - get NaN Third, passes a hardcoded string directly to the second function - works.
Code is shown below. How do I get a querstring value to be converted to Javascript Date
<head>
<SCRIPT LANGUAGE="JavaScript" SRC="./date.format.js">
</SCRIPT>
</head>
<script>
function DateTest(dt)
{
var myDate = new Date(dt);
alert(myDate);
var newDate = myDate.format("isoDateTime");
document.write(newDate);
alert(newDate);
}
function QueryDateTest(parm)
{
DateTest(getRequestParameter(parm));
}
function getRequestParameter( name ) {
var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 ){
var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
var aQueryString = strQueryString.split("&");
for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
if (aQueryString[iParam].indexOf(name.toLowerCase() + "=") > -1 ){
var aParam = aQueryString[iParam].split("=");
strReturn = aParam[1];
break;
}
}
}
alert(unescape(strReturn));
return(unescape(strReturn.toString()));
}
</script>
<body>
<input type="button" id="hello-world1" value="QueryString" onClick="getRequestParameter('create');" />
<input type="button" id="hello-world2" value="ISODate" onClick="QueryDateTest('create');" />
<input type="button" id="hello-world3" value="HardCoded" onClick="DateTest('11/10/2009');" />