Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date format replace

Status
Not open for further replies.

apex82

Programmer
Mar 2, 2009
127
GB
Hi,

I would like to format a date in a form field so when a user adds

01012001

This would be returned as

01/01/2001

I’ve searched Google for an example but can’t find anything.

Can anyone help?

Thanks.


 
Assuming the date entered will ALWAYS be 8 digits, you can use:

Code:
var dateStr = '01042009';
var dd = dateStr.substr(0, 2); // 01
var mm = dateStr.substr(2, 2); // 04
var yyyy = dateStr.substr(4);  // 2009

I'd recommend using 'onblur' on the input to run its value through that code.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top