Liquid UI - WS Reference Library

Get current date


Prerequisites


Purpose

Get today's date in user's date format.


User Interface


 

Get Today's Date button will populate today's date in user format.


Liquid UI Script

//SAPLSMTR_NAVIGATION.E0100.sjs

// Author: Synactive, Inc. [1065 E. Hillsdale Blvd, Foster City, CA, 94404, USA]
// Email: support@guixt.com; sales@guixt.com;
// Contact: 650.341.3310
// Version: 1.0.0.0
del("X[IMAGE_CONTAINER]");
inputfield ([2,4], "Date", [2,16],{"name":"z_todaydate", "size":10});
pushbutton([4,8], "Get Today's Date","/nsu3",{"size":[2,22], "process":today_date});
function today_date(){
// Maintain User Profile
onscreen 'SAPLSUU5.0100'
   enter('=DEFA');

// Maintain User Profile
onscreen 'SAPLSUU5.0100'
    set("V[z_dateformat]", "&F[Date format]");
    z_dateformat = z_dateformat.trim();    
    z_todaydate = getTodaysDate(z_dateformat);                    
    enter('/n');    

}
//Function prototypes, to remove blank spaces from variable values
////////////////////////////////////////////////////////////////////////////////////////////
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
//Function to get todays date with user format
////////////////////////////////////////////////////////////////////////////////////////////
function getTodaysDate(dformat) {
    var z_date = new Date();
    println(">>>>>>>>>>>>>>>>>",z_date);
    var str = "";
    switch(dformat)
    {
        case '1':
        {
            str = padString(z_date.getDate(),2,PADDING_LEFT,"0") + "." + padString((z_date.getMonth()+1),2,PADDING_LEFT,"0") + "." + z_date.getFullYear();
        }
        break;
        
        case '2':
        {
           str = padString((z_date.getMonth()+1),2,PADDING_LEFT,"0") + "/" + padString(z_date.getDate(),2,PADDING_LEFT,"0") + "/" + z_date.getFullYear();
        }
        break;

        case '3':
        {
           str = padString((z_date.getMonth()+1),2,PADDING_LEFT,"0") + "-" + padString(z_date.getDate(),2,PADDING_LEFT,"0") + "-" + z_date.getFullYear();
        }
        break;

        case '4':
        {
           str = z_date.getFullYear() + "." + padString((z_date.getMonth()+1),2,PADDING_LEFT,"0") + "." + padString(z_date.getDate(),2,PADDING_LEFT,"0");
        }
        break;

        case '5':
        {
           str = z_date.getFullYear() + "/" + padString((z_date.getMonth()+1),2,PADDING_LEFT,"0") + "/" + padString(z_date.getDate(),2,PADDING_LEFT,"0");
        }
        break;
        
        case '6':
        {
           str = z_date.getFullYear() + "-" + padString((z_date.getMonth()+1),2,PADDING_LEFT,"0") + "-" + padString(z_date.getDate(),2,PADDING_LEFT,"0");
        }
        break;
        case '7':
        {
            str = padString(z_date.getDate(),2,PADDING_LEFT,"0") + padString((z_date.getMonth()+1),2,PADDING_LEFT,"0") +z_date.getFullYear();
        }
        break;
    }
    println(str);
    return str;
}
//Function to pad a string with characters
////////////////////////////////////////////////////////////////////////////////////////////
const PADDING_LEFT = 0;
const PADDING_RIGHT = 1;
function padString(source,length,direction,character) {
    var loop;
    var output = "";
    var sourceLength = 0;
    set('V[z_source]',source);
    if(z_source) {
        sourceLength = z_source.length;
    }
    
    switch(direction) {
    case PADDING_LEFT:
        for(loop = 0; loop < (length - sourceLength); loop++) {
            output += character;
        }
        output = output + z_source;
        break;
        
    case PADDING_RIGHT:
        for(loop = 0; loop < (length - sourceLength); loop++) {
            output += character;
        }
        output = z_source + output;
        break;
    }
    return output;
}

 

 

 


Was this information helpful? Send Feedback