locked
JavaScript- compare today's date with CRM Form date field RRS feed

  • Question

  • Hi Guys,

    On my entity form I have date field.

    'Onchange' event of this field I want to check if user has entered date is less then today's date. if yes then i want show error. CRM form date field is in dd/mm/yyyy format.

    I have put following code but it's not working. Seems to be simple at first place but I think I am missing something very obvious here.

    Here is the code.

    var today = new Date();

    var curr_date = today.getDate();
    var curr_month = today.getMonth();
    curr_month = curr_month + 1;
    var curr_year = today.getFullYear();

    var constructdate = curr_date + '/'+ curr_month + '/'+ curr_year;

    if(crmForm.all.new_startdate.DataValue < constructdate)

    {

     alert('Start Date can not be before today's date');

    Can someone please guide me !!

    Many Thanks.

     

     

     

     


    Thank you all for your help - CRM Thirsty
    Friday, October 29, 2010 6:23 AM

Answers

  • check this.

    var today = new Date();


    if(crmForm.all.new_startdate.DataValue.valueOf() < today.valueOf())

    {

     alert('Start Date can not be before today's date');

    }


    Jai Ho CRM http://mscrmkb.blogspot.com Skype - amol.gholap

    Mark as answer if a post has answered the question
    Friday, October 29, 2010 6:45 AM

All replies

  • check this.

    var today = new Date();


    if(crmForm.all.new_startdate.DataValue.valueOf() < today.valueOf())

    {

     alert('Start Date can not be before today's date');

    }


    Jai Ho CRM http://mscrmkb.blogspot.com Skype - amol.gholap

    Mark as answer if a post has answered the question
    Friday, October 29, 2010 6:45 AM
  • Hi,

    Try this,

    function CheckTheDate(txtname)
    {
        var Today = new Date();
        if ((txtname.DataValue == "undefined") || (txtname.DataValue == null)) {
            return "No date defined";
        }
        if (txtname.DataValue > Today) {
            return "Greater";
        }
        if (txtname.DataValue < Today) {
            return "Less";
        }
        if (txtname.DataValue == Today) {
            return "Same as todays date";
        }
    }

    Thanks

    Friday, October 29, 2010 9:46 AM