Page 1 of 1

ddmmyyyy to mmddyyyy in Javascript

Posted: Fri Mar 06, 2009 3:10 pm
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 ?

Re: ddmmyyyy to mmddyyyy in Javascript

Posted: Fri Mar 06, 2009 3:34 pm
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];