components_node/functions-generic.js
/**
     * Date format for SQL write.
     * @static
     * @param {string | Date} dateInput  
     * @param {string} configDateFormat 1 - PT | 2 - UK
     * @returns {string | Date} If `configDateFormat` is empty, will return Date
     * @example
     * SyncSystemNS.FunctionsGeneric.dateSQLWrite(dateObjName)
     */
Date format for SQL write.
Date format for SQL write .
static dateSQLWrite(dateInput, configDateFormat = "")
    {
        let strReturn = "";
        let dateObj = new Date();
        let arrDateFull = [];
        let arrDate = [];
        let strDateTime = "";
        if(dateInput)
        {
            if(!configDateFormat)
            {
                dateObj = dateInput;
                let dateYear = dateObj.getFullYear();
                let dateDay = dateObj.getDate();
                let dateMonth = (dateObj.getMonth() + 1);
                let dateHour = dateObj.getHours();
                let dateMinute = dateObj.getMinutes();
                let dateSecond = dateObj.getSeconds();
                let dateFormated = dateYear + "-" + dateMonth + "-" + dateDay;
                if(dateDay < 10)
                {
                    dateDay = "0" + dateDay;
                }
                if(dateMonth < 10)
                {
                    dateMonth = "0" + dateMonth;
                }
                if(dateHour < 10)
                {
                    dateHour = "0" + dateHour;
                }
                if(dateMinute< 10)
                {
                    dateMinute = "0" + dateMinute;
                }
                if(dateSecond < 10)
                {
                    dateSecond = "0" + dateSecond;
                }
                strReturn = dateFormated + " " + dateHour + ":" + dateMinute + ":" + dateSecond;
            }
            if(configDateFormat)
            {
                if(dateInput.includes("/"))
                {
                     values definitions.
                        arrDateFull = dateInput.split(" ");
                        arrDate = arrDateFull[0].split("/");
                        if(arrDateFull[1])
                        {
                            strDateTime = arrDateFull[1];
                        }
                    if(configDateFormat == 1)
                    {
                        strReturn = arrDate[2] + "-" + arrDate[1] + "-" + arrDate[0];
                    }
                    if(configDateFormat == 2)
                    {
                        strReturn = arrDate[2] + "-" + arrDate[0] + "-" + arrDate[1];
                    }
                    if(strDateTime != "")
                    {
                        strReturn = strReturn + " " + strDateTime;
                    }
                }else{
                    strReturn = null;
                }
            }
        }
        return strReturn;
    }
static dateSQLWrite ( dateInput , configDateFormat = "" ) { let strReturn = "" ; let dateObj = new Date ( ) ; let arrDateFull = [ ] ; let arrDate = [ ] ; let strDateTime = "" ; if ( dateInput ) { if ( ! configDateFormat ) { dateObj = dateInput ; let dateYear = dateObj . getFullYear ( ) ; let dateDay = dateObj . getDate ( ) ; let dateMonth = ( dateObj . getMonth ( ) + 1 ) ; let dateHour = dateObj . getHours ( ) ; let dateMinute = dateObj . getMinutes ( ) ; let dateSecond = dateObj . getSeconds ( ) ; let dateFormated = dateYear + "-" + dateMonth + "-" + dateDay ; if ( dateDay < 10 ) { dateDay = "0" + dateDay ; } if ( dateMonth < 10 ) { dateMonth = "0" + dateMonth ; } if ( dateHour < 10 ) { dateHour = "0" + dateHour ; } if ( dateMinute < 10 ) { dateMinute = "0" + dateMinute ; } if ( dateSecond < 10 ) { dateSecond = "0" + dateSecond ; } strReturn = dateFormated + " " + dateHour + ":" + dateMinute + ":" + dateSecond ; } if ( configDateFormat ) { if ( dateInput . includes ( "/" ) ) { arrDateFull = dateInput . split ( " " ) ; arrDate = arrDateFull [ 0 ] . split ( "/" ) ; if ( arrDateFull [ 1 ] ) { strDateTime = arrDateFull [ 1 ] ; } if ( configDateFormat == 1 ) { strReturn = arrDate [ 2 ] + "-" + arrDate [ 1 ] + "-" + arrDate [ 0 ] ; } if ( configDateFormat == 2 ) { strReturn = arrDate [ 2 ] + "-" + arrDate [ 0 ] + "-" + arrDate [ 1 ] ; } if ( strDateTime != "" ) { strReturn = strReturn + " " + strDateTime ; } } else { strReturn = null ; } } } return strReturn ; }
Date format for SQL write.
Date format for SQL write .
//Variables. //---------------------- //---------------------- //Detect input format (2000-30-01 or 01/30/2000). //Logic - returns yyyy-mm-dd hh:MM:ss. //---------------------- //ref: https://blog.dotmaui.com/2017/10/17/javascript-current-date-with-format-yyyy-mm-dd-hhmmss/ //Variable value. //let dateObj = new Date(dateInput); //Variables //Ajustments. //---------------------- //Forced format. //---------------------- //Variables values definitions. /**/ //if(dateInput.length > 10) //{ //if(typeof arrDateFull[1] !== "undefined") //}else{ //arrDate = dateInput.split("/"); //} //arrDate = dateInput.split("/"); //portuguese dd/mm/yyyy //britanic mm/dd/yyyy /**/ //---------------------- //Usage. //---------------------- //SyncSystemNS.FunctionsGeneric.dateSQLWrite("15/02/2020", gSystemConfig.configBackendDateFormat) //----------------------