IT Community - Software Programming, Web Development and Technical Support

Convert String to Date: new Date(string)

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(...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Flash Actionscript Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-05-2008, 03:18 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Convert String to Date: new Date(string)

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...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-05-2008, 08:59 PM
aramesh aramesh is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 71
aramesh is on a distinguished road
Default Re: Convert String to Date: new Date(string)

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-07-2008, 12:49 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: Convert String to Date: new Date(string)

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...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-07-2008, 08:24 PM
aramesh aramesh is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 71
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 08:28 PM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 12:10 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0