cancel
Showing results for 
Search instead for 
Did you mean: 

FormatDate() equivalent in DS

Former Member
0 Kudos

Hi

  Is there a easy way to apply Date Format in Design Studio?

  I understand it is currently predetermine by Web Browser / BI LaunchPad settings (Preferred Viewing Locale).

  What if I need to preset it to particular date format regardless of individual settings or to something less ambiguous

- Displaying month in Mmm - 01 May 2014 rather than 01/05/2014 or 05/01/2014

- WebI equilvalent to FormatDate() functionality in DS?

   I am using lastRefreshedAt() to retrieve the date at the moment but have no luck formatting it


e.g.

TXT_REFRESH_LABEL.setText("Last Refresh : " + DATASOURCE.getInfo().lastRefreshedAt );

Thanks,

Ken

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Ken,

the answer to your question can be also found here:

As of now (DS 1.3) there are no date conversion scripting functions available yet. See also a similar question here:

To get the current date you can use: APPLICATION.getInfo().dateNowInternalFormat

that works independently of the user locale.

You can create simple if statements to create your own formatting.

Example:


TEXT_1.setText(APPLICATION.getInfo().dateNowInternalFormat);

var monthNum = Convert.subString(APPLICATION.getInfo().dateNowInternalFormat, 4,6);

var monthStr3 = "";

var monthStrFull = "";

      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";}

TEXT_1.setText(TEXT_1.getText() + " " + monthStr3 + " " + monthStrFull);

var day = Convert.subString(APPLICATION.getInfo().dateNowInternalFormat, 6,8);

var year = Convert.subString(APPLICATION.getInfo().dateNowInternalFormat, 0,4);

TEXT_2.setText(day +" "+ monthStr3 +" "+ year);

// http://en.wikipedia.org/wiki/English_numerals#Ordinal_numbers

var day123 = "th";

      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";}

TEXT_3.setText(day+day123+" "+monthStr3+" "+year +" ; "+ day+day123+" "+monthStrFull+" "+year);

Result of this code (screenshot):

Kind Regards,

David

Former Member
0 Kudos

Thanks for the feedback David.

Convert.SubString function will only work if the user locale is known in advance.

     e.g. dateNowInternalFormat() - YYYYMMDD

Most other functionality are user/browser locale dependent

     getInfo().lastRefreshedAt

     getInfo().lastDataUpdate

It will be difficult to know where to start and stop (Convert.Substring) as there are so many different format.

     e.g.  MM/d/YYYY

            dd/MM/YYYY

            DD Mmm YYYY

            d/M/yy....The list go on..

Is there a function that return user locale as this may help?

To further complicate thing, some of these functionality have time stamp as well (hh:mm:ss).

In other BOBJ tools (WebI, Crystal) , the coding is one simple liner that takes care of all scenarios (including time stamp)

    =FormatDate(CurrentDate();"d Mmm yyyy hh:mm:ss")

To get similar affect in Design Studio, it will be extremely more complicated.

Look like a post on SAP Idea Place for another DS limitation.

Cheers,
Ken

Former Member
0 Kudos

Hi Ken,

APPLICATION.getInfo().dateNowInternalFormat is the only internal scripting method which returns the date in the same format not depending on a user locale language setting. All the other getInfo() date related methods are user locale language dependent in regards to their formatting.

There is no function that would return the user locale or similar information to help you determine what number represents the day information and what the month and year information.

One idea would be to concentrate on the top 90%-95% of all cases (if possible): choose the 3-4 most common user locale options and if you can determine those, than use your own custom formatting, for all the others use the default formatting.

For example look for "/" or for "." as separator by using "convert indexOf" and try to check the information from "APPLICATION.getInfo().dateNow" against "APPLICATION.getInfo().dateNowInternalFormat" to determine which part of the APPLICATION.getInfo().dateNow ist day, month and year, then you have found out how to use (where day, month and year starts and ends) "convert subString" on the other user locale dependent date methods.

Alternatively maybe it is easier to find out some user locale information in an own custom SDK component where you should have access to more information or at least to more javascript and do some date formatting there.

Regards,

David

Answers (1)

Answers (1)

Karol-K
Advisor
Advisor
0 Kudos

Hi,

try out desing studio 1.3 SP1 and my Simple Date Object SDK:


Design Studio SDK: Simple Date Object Component

perhaps this is the direction you search for. you can comment the document if you wish some extensions.

Regards, Karol