Skip to Content

Format DS_01.getInfo().lastDataUpdate (Design Studio)

Dear all,

I received a question from my customer, they want to show the last data update in the following format in Design Studio:

Output wanted: 10th January 2017

If you display the output of DS_01.getInfo().lastDataUpdate, it will give:

1/10/17 10:08 AM

How can I convert a datefield into a string as the output I wanted?

I'm working with Design Studio Version: 16.0.5

Regards,

Pieter Verstraeten

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Jan 13, 2017 at 11:31 AM

    Hello Pieter,

    Reading all the links https://answers.sap.com/questions/64013/need-to-display-date-in-design-studio-as-ddmmyyyy.html it sounds like it is based on the browser settings

    You may want to consider trying the Community SDK as Franck mentions here: https://archive.sap.com/discussions/thread/3881502 also discussed here: https://archive.sap.com/documents/docs/DOC-57391

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 16, 2017 at 09:03 AM

    Hi Tammy,

    Thanks for this answer, this was based on the browser setting. I've made a function that will convert the date into the right format.

    Regards,

    Pieter

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 23, 2017 at 08:12 AM

    Hi Koen and other Design Studio developers,

    Here is the code, I've created two functions:

    1. LastDataUpdate --> you need to create input parameter "ip_type_output" of type "int"

    2. ConvertDateFormat --> you need to create 4 input parameters: "ip_year", "ip_month", "ip_day" of type "string" and "ip_type_output" of type "int"

    If they are helpfull, please let me know.

    With regards,

    Pieter

    FUNCTION "LastDataUpdate"
    
    // This function will deliver the last data update. The SAP BI launchpad has a standard format setting like M/D/YY U:M
    // When the user has changed his/her setting in the preferences, we need to catch the correct dateformat
    
    
    // Declaration of variables
    var dataupdate = DS_01.getInfo().lastDataUpdate;
    var arr = [""];
    var	dataupdate_year = "";
    var	dataupdate_month = "";
    var	dataupdate_day = "";
    var ReturnValue = "";
    
    
    // Check the dateformat, 
    if (dataupdate.indexOf("/") > 0) {		// This is the standard browsersetting
    	arr = dataupdate.split("/");
    	dataupdate_year = arr[2];
    	dataupdate_month = arr[0];
    	dataupdate_day = arr[1];
    }else if (dataupdate.indexOf("-") > 0) {	// User has changed his browsersetting manually to English
    	arr = dataupdate.split("-");
    	dataupdate_year = arr[2];
    	dataupdate_month = arr[1];
    	dataupdate_day = arr[0];	
    }
    
    
    // Modify the year
    dataupdate_year = "20" + dataupdate_year.substring(0,2);
    
    
    // Modify the month
    if ( dataupdate_month.length == 1 ) {
    	dataupdate_month = "0" + dataupdate_month;
    }
    
    
    // Modify the day
    if ( dataupdate_day.length == 1 ) {
    	dataupdate_day = "0" + dataupdate_day;
    }
    
    
    // Convert the date into the correct date format
    ReturnValue = "Last data update: " + FUNCTIONS.ConvertDateFormat(dataupdate_year, dataupdate_month, dataupdate_day, ip_type_output);
    
    
    return ReturnValue;
    
    
    
    
    FUNCTION "ConvertDateFormat"
    
    // Declaration of variables
    var date = ip_year + ip_month + ip_day;
    
    
    var day = ip_day;
    var monthNum = ip_month;
    var monthStr3 = "";
    var monthStrFull = "";
    var year = ip_year;
    var day123 = "th";
    var ReturnValue = "";
    
    
    // Initialize the date in format YYYYMMDD
    SIMPLEDATE.initializeWithInternalDate(date);
    
    
    // Set the texts for month value
    if (monthNum == "01") {monthStr3 = "Jan"; monthStrFull = "January";}
    else if (monthNum == "02") {monthStr3 = "Feb"; monthStrFull = "February";}
    else if (monthNum == "03") {monthStr3 = "Mar"; monthStrFull = "March";}
    else if (monthNum == "04") {monthStr3 = "Apr"; monthStrFull = "April";}
    else if (monthNum == "05") {monthStr3 = "May"; monthStrFull = "May";}
    else if (monthNum == "06") {monthStr3 = "Jun"; monthStrFull = "June";}
    else if (monthNum == "07") {monthStr3 = "Jul"; monthStrFull = "July";}
    else if (monthNum == "08") {monthStr3 = "Aug"; monthStrFull = "August";}
    else if (monthNum == "09") {monthStr3 = "Sep"; monthStrFull = "September";}
    else if (monthNum == "10") {monthStr3 = "Oct"; monthStrFull = "October";}
    else if (monthNum == "11") {monthStr3 = "Nov"; monthStrFull = "November";}
    else if (monthNum == "12") {monthStr3 = "Dec"; monthStrFull = "December";}
    
    
    // Set the texts for day value
    if (day == "01" || day == "21" || day == "31") {day123 = "st";}
    else if (day == "02" || day == "22") {day123 = "nd";}
    else if (day == "03" || day == "23") {day123 = "rd";}
    
    
    // Determine output type
    if (ip_type_output == 1) {
    	ReturnValue = day+day123+" "+monthStrFull+" "+year;		// Output like 28th January 2017
    }else if (ip_type_output == 2) {
    	ReturnValue = day+day123+" "+monthStr3+" "+year;		// Output like 28th Jan 2017
    }else if (ip_type_output == 3) {
    	ReturnValue = day +" "+ monthStr3 +" "+ year;			// Output like 28 Jan 2017
    }
    
    
    return ReturnValue;
    
    Add comment
    10|10000 characters needed characters exceeded