CA Service Management

 View Only
  • 1.  Help with validation Dates using JavaScript

    Posted Aug 27, 2019 05:47 PM
      |   view attached

    Hi all.

    I developed a JavaScript function to prevent that call_back_date field be less than alg.time_stamp date (activity date). Date is in format DD/MM/YYYY

    The problem is that it's seems like comparing if the day of call back date is greater than day of activity date. Even if the month is greater, if the day is minor it's considering call back less than activity date.

    I attached a screenshot with an example. I appreciate any help that let me to solution.

    Thanks and regards.

     

    function zValidateSchedDate(){

        
        var zStartDate, zSchedDate;
        var zSatus = document.main_form.elements["SET.status"].value;
        
             zStartDate = document.main_form.elements['SET.alg.time_stamp'].value;
            zSchedDate = document.main_form.elements['SET.call_back_date'].value;
            
            if((zSchedDate <= zStartDate) && (zSatus == "atdschedule")){
                zDisplayMessage("Schedule date needs to be a future date!");
                return false;
            }else{
                return true;
            }
    }

     callbackdate.png



  • 2.  RE: Help with validation Dates using JavaScript

    Broadcom Employee
    Posted Aug 27, 2019 09:06 PM

    Hello Isaque,

    Is JavaScript treating this as a string rather than a date? 


    Try searching the web for "JavaScript convert string to datetime" and see what comes up.

    Eg:
    https://www.geeksforgeeks.org/how-to-convert-javascript-datetime-to-mysql-datetime/
    https://stackoverflow.com/questions/5510580/convert-string-to-datetime/24642753

    Thanks, Kyle_R.






  • 3.  RE: Help with validation Dates using JavaScript
    Best Answer

    Posted Aug 27, 2019 09:11 PM
    Solved. As you mentioned the values are string and are compared as string and not as date. With both values, did : zstart_date = new Date(document.......)


  • 4.  RE: Help with validation Dates using JavaScript

    Broadcom Employee
    Posted Aug 27, 2019 09:54 PM

    Excellent!

    Thanks for the confirmation.

    Kyle_R.




  • 5.  RE: Help with validation Dates using JavaScript

    Posted Nov 11, 2019 10:28 AM
    Hey Guys,

    It is good to see that you got your answer.

    For other guys who really want to learn how to setup Datepicker in React and Angular, check out the following tutorials. It has really helped me a lot.

    React Datepicker Example

    Angular Datepicker Example