ddmmyyyy to mmddyyyy in Javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
millsy007
Forum Commoner
Posts: 78
Joined: Wed Jul 02, 2008 7:00 pm

ddmmyyyy to mmddyyyy in Javascript

Post by millsy007 »

I have recently changed my page so my date that is held in a textbox is in the European Format, ie DD/MM/YYYY

The problem is all of my other javascript functions expect it in the 'normal' format.
Is there a way I can change the format I now have it in back, so:
datevariable = document.getElementById('date').value;
switches back from dd/MM/yyyy to MM/dd/yyyy

Hi I try to do this within my function:

var tmp = document.getElementById('date').value;
var tmp = ddmmyyyy.split('/');
var date = tmp[1]+'/'+tmp[0]+'/'+tmp[2];


But it doesnt work ?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: ddmmyyyy to mmddyyyy in Javascript

Post by jayshields »

millsy007 wrote: Hi I try to do this within my function:

var tmp = document.getElementById('date').value;
var tmp = ddmmyyyy.split('/');
var date = tmp[1]+'/'+tmp[0]+'/'+tmp[2];


But it doesnt work ?
Surely you'll want:

Code: Select all

 
    var tmp = document.getElementById('date').value;
    var tmp = tmp.split('/');
    var date = tmp[1]+'/'+tmp[0]+'/'+tmp[2];
 
Post Reply