Jump to content

Switching Date Format


millsy007

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/148242-switching-date-format/
Share on other sites

Might be an easier way, but this will work. You can use it to covnert back and forth. Whatever format you are inputting you will get the opposite out.

 

function reverseDayMonth(dateStr)
{
    dateArr = dateStr.split('/');
    return dateArr[1]+'/'+dateArr[0]+'/'+dateArr[2];
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.