This is a discussion on Convert String to Date: new Date(string) within the Flash Actionscript Programming forums, part of the Web Development category; Hi, I have this problem strd="Tue Apr 22 02:57:29 GMT+0100 2003"; d = new Date(...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi, I have this problem strd="Tue Apr 22 02:57:29 GMT+0100 2003"; d = new Date(strd) trace(d); ->invalide date ??? So how do you convert this date??? Regards, A.Ramesh
__________________ The OXYGEN Delivers edgy, intelligent Technology to all... |
| Sponsored Links |
| |||
| Hi, Actionscript works slightly differently. If you want to set the date object you will need to use the relevant set methods for the new object you create. Take a look at this link for a very detailed run down. http://www.macromedia.com/support/fl...ionary153.html Regards, A.Ramesh |
| |||
| Thought so. argh. -> know of any good convertion function to do this fast -> I am pulling from a db so... or hey -> maybe I can convert it in sql so the string swaps the column to an adequate format..
__________________ The OXYGEN Delivers edgy, intelligent Technology to all... |
| |||
| 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 A.Ramesh Last edited by aramesh : 03-07-2008 at 08:28 PM. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Check that a string contains a date. | itbarota | HTML, CSS and Javascript Coding Techniques | 2 | 03-11-2008 08:01 PM |
| Convert a date in milliseconds back to a date string | itbarota | HTML, CSS and Javascript Coding Techniques | 2 | 03-03-2008 08:03 PM |
| convert a text string into a Date object. | itbarota | HTML, CSS and Javascript Coding Techniques | 2 | 02-12-2008 05:37 AM |
| How do I work out the date seven days before a text string mm/dd/yy? | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 01-01-2008 07:42 PM |
| How can I compare a date in a string with todays date? | itbarota | HTML, CSS and Javascript Coding Techniques | 2 | 12-18-2007 10:02 PM |