View Single Post
  #4 (permalink)  
Old 03-07-2008, 09:24 PM
aramesh aramesh is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 72
aramesh is on a distinguished road
Default Re: Convert String to Date: new Date(string)

Hi,
I wrote this method to do that for me a while back. As long as the format of the database element is ODBC, this should work.

ActionScript Code:
Code:
String.prototype.stringToDate = function() {
    // establish the string to be converted to a date
    // ----------------------------------------------------------------
    var strODBC = this.toString();
    
    // convert various date parts into numbers
    // ----------------------------------------------------------------

    // get year and convert to a number
    var strYear = strODBC.substr(strODBC.lastIndexOf(" ")+1);
    var numYear = number(strYear);

    // get month and convert to a number
    var strMonth = strODBC.substr(4,3);
    var numMonth;
    for(i=0;i<monArr.length; i++){
	 if(monArr[i]==strMonth){
		numMonth = i;
		break;
	 }
     }
		
    
    // get day (i.e. date) and convert to a number
    var strDate = strODBC.substr(8,2);
    strDate = strDate.Trim();
    var numDate = number(strDate);
    // return a new date object with the proper date numbers
    // ----------------------------------------------------------------
    var thisDate = new Date(numYear,numMonth,numDate);
    return thisDate;
} 
// end string.stringToDate() method 
Regards,

A.Ramesh

Last edited by aramesh : 03-07-2008 at 09:28 PM.
Reply With Quote