Tuesday, 22 July 2014

Convert and Validate Datetime dd/mm/yyyy to mm/dd/yyyy using javascript

//Script

var d1 = "18-10-2014";
var d2 = "18-9-2014";                  
var split = d1.split('-');
var s2= d2.split('-');
var initial=[split[1], split[0], split[2]].join('/');
var i2=[s2[1], s2[0], s2[2]].join('/');
var da =new Date(initial);
var daq =new Date(i2);
var da1=new Date(da.getFullYear(),da.getMonth(),da.getDate());
var da2=new Date(daq.getFullYear(),daq.getMonth(),daq.getDate());
if(da1>da2)
{
alert(1);
}
if(da1<da2)
{
alert(2);
}

//Result


No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...