Comparing Dates

A little function in Javascript that compares two dates: if the field date is older than current date, an alert is shown.

The format for the parameter date_field is dd/mm/yyyy. For the dd/mm/yy format a casting is required


function IsOldDate(date_field){

var date_array = date_field.split("/");
var df = date_array[0];
var mf = date_array[1];
var yf = date_array[2];


var currentTime = new Date();
var mt = currentTime.getMonth()+1; //-- javascript begins months in 0
var dt = currentTime.getDate();
var yt = currentTime.getFullYear();

alert(compare_currentdate +" date "+compare_datefield);

if( (compare_currentdate) > (compare_datefield) ){
alert("the date is older than current date!");
return (true);
return (false);