cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP Build Apps - Convert Date from OData

ITM_Benedikt
Explorer
2,223

Hello all,

Whenever I use a date from an Odata service, it is formatted like this:

With the usular functions in SAP Build Apps, I cannot convert it to any other date format like "dd.mm.yyyy".

As I'm using a standard OData service (API_SALES_ORDER_SRV) I can't change the type of the field to string. Has anyone encountered this problem and can help me?

Thanks

Benedikt

Accepted Solutions (1)

Accepted Solutions (1)

quentinvillers
Explorer
0 Likes

Hello,

You can create a quick subflow with Javascript to transform those Date, adapting your data response.
You could even do this with a Formula but quite cumbersome to maintain.

I have built a function that gives me time ago (E.g. 04-10-2023 was 1 year go.)
This could be a quick add-on that you can use whenever you need to display those date.

Quentin

ITM_Benedikt
Explorer

Thanks Quentin,

I solved it by creating a rule. The part I didn't know was that you have to convert the epoch date into a number.

FORMAT_DATETIME_LOCAL(DATETIME(NUMBER(SUBSTRING(data.A_SalesOrder1.RequestedDeliveryDate, 6,19))), "DD.MM.YYYY")
Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Likes

bekra Thanks for this tip. What do you mean you created a "rule" in SAP Build Apps?

Answers (2)

Answers (2)

nishantbansal91
Active Contributor
0 Likes

Hello team,

 

Just for reference for other community members,

 

I have used below javascript code to convert the date to oData date format. 

I have fired the event once the date field is changed to call the Javascript and store it into different variable. 

const inputDateTime = inputs.input1;
const date = new Date(inputDateTime);;

// Step 2: Set the time to the start of the day
date.setUTCHours(0, 0, 0, 0);
// Step 3: Format the resulting date to the desired string format
const year = date.getUTCFullYear();
// because there is no less equal to operator in oData supported by JAVASCRIPT so need to -1 in From Date.
date.setUTCDate(date.getUTCDate() - 1);

const month = String(date.getUTCMonth() + 1).padStart(2, '0'); // Months are zero-based
const day = String(date.getUTCDate()).padStart(2, '0');
const hours = String(date.getUTCHours()).padStart(2, '0');
const minutes = String(date.getUTCMinutes()).padStart(2, '0');
const seconds = String(date.getUTCSeconds()).padStart(2, '0');

var result1 = year + '-' + month + '-' + day + 'T' + hours + ':' + minutes + ':' + seconds ;
return{ result : result1 };

navalega0109
Participant
0 Likes

Hello @ITM_Benedikt ,

 

Use the below function inside formula section to change the format you wish for.

FORMAT_DATETIME_LOCAL(date/time, format)

 Example

FORMAT_DATETIME_LOCAL("2019-07-11T13:06:15+03:00", "DD.MM.YYYY")

Output:

11.07.2019