...

View Full Version : dd/mm/yy --> mm/dd/yy



ShMiL
10-13-2003, 10:23 AM
dd/mm/yy --> mm/dd/yy
Any known script for this?

Or better, any DateDiff script that works with the dd/mm/yy format?

thanks:cool:

nnichols
10-13-2003, 02:54 PM
function dateDiff(date1, date2)
{
// EXPECTS 2 DATES IN dd/mm/yy or dd/mm/yyyy FORMAT
var date1Array = date1.split('/');
var date2Array = date2.split('/');

// IF LENGTH OF DATE IS 2 CHARS CONVERT TO 4 CHARS
if (date1Array[2].length == 2)
{
if (date1Array[2] > 70)
date1Array[2] = '19'+date1Array[2];
else
date1Array[2] = '20'+date1Array[2];
}

if (date2Array[2].length == 2)
{
if (date2Array[2] > 70)
date2Array[2] = '19'+date2Array[2];
else
date2Array[2] = '20'+date2Array[2];
}

// CREATE DATE OBJECTS
var date1Obj = new Date(date1Array[2], date1Array[1]-1, date1Array[0]);
var date2Obj = new Date(date2Array[2], date2Array[1]-1, date2Array[0]);

var oneDay=1000*60*60*24;

// CONVERT DATE OBJECTS TO TIMESTAMPS
var date1Stamp = date1Obj.getTime();
var date2Stamp = date2Obj.getTime();

// CALCULATE NUMBER OF DAYS BETWEEN DATES
if (date1Stamp > date2Stamp)
alert(Math.ceil((date1Stamp - date2Stamp) / oneDay));
else
alert(Math.ceil((date2Stamp - date1Stamp) / oneDay));
}Hope this helps

ShMiL
10-13-2003, 03:23 PM
That's great! Thanks alot! :thumbsup: :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum