AS2 convert string to date


/ Published in: ActionScript
Save to your folder(s)

This function takes a string containing a date in "mm/dd/yyyy" or "m/d/yyyy" format and converts it to a date object in AS2.


Copy this code and paste it in your HTML
  1. function convertMyDate(strToCheck):Date {
  2. var uryear:String;
  3. var urmonth:String;
  4. var urday:String;
  5. var newDate:Date;
  6.  
  7. uryear = strToCheck;
  8. uryear = uryear.substr(uryear.length - 4, 4);
  9.  
  10. urmonth = strToCheck;
  11. urmonth = urmonth.substr(0, urmonth.indexOf("/"));
  12.  
  13. urday = strToCheck;
  14. urday = urday.substr(0, urday.length - 5);
  15. urday = urday.substr(2, urday.indexOf("/")+1);
  16.  
  17. newDate = new Date(Number(uryear),Number(urmonth)-1,Number(urday));
  18.  
  19. return(newDate);
  20. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.