Friday, 16 October 2015

Javascript : Date Comparison

jQuery.validator.addMethod("startDated", function (value, element, params) { 
    var adata = value.split('-');
    var gg = parseInt(adata[0],10);
    var mm = parseInt(adata[1],10);
    var aaaa = parseInt(adata[2],10);

    var adata2 = $(params).val().split('-');
    var gg2 = parseInt(adata2[0],10);
    var mm2 = parseInt(adata2[1],10);
    var aaaa2 = parseInt(adata2[2],10);

    value = mm+'-'+gg+'-'+aaaa;
    params = mm2+'-'+gg2+'-'+aaaa2;

    var check = false;
    if((new Date(aaaa,mm-1,gg).getTime() > new Date(aaaa2,mm2-1,gg2).getTime())) 
    {
        check = true;
    } else
        check = false;
    return this.optional(element) || check;
},'Hendaklah lebih besar dari tarikh sebelumnya');

Type by :
Che Wahida Binti Che Pauzur

0 comments:

Post a Comment