cancel
Showing results for 
Search instead for 
Did you mean: 

Date is in UNIX timestamp format in OData , how to convert it

0 Kudos

Hi,

After setting OData Model, date is shown in a UNIX Time stamp format.

date: "/Date(1500854400000)/

I want to display this date into readable form and also need to add 2 days on the date(date+2)

Do I need to convert this format to date format

Please help

Accepted Solutions (0)

Answers (3)

Answers (3)

ericci
Active Contributor

You can follow the Date Formatter tutorial. In the Formatter, you can manipulate the Date and add 2 days and return the manipulated one.

0 Kudos

I am binding these data in to a table, I have some condition for calculating the scheduled date, can we do this in DATE FORMATER with below condition base? I think it should be done before binding the data. right? but the issue is date is showing in timestamp format.

IF DistributionChannel = '10' OR DistributionChannel = '30' OR DistributionChannel = '50' . "
IF katr2 = '01'. "
ScheduleDate = ScheduleLineDate + 20.
ELSEIF IncoTerm1 = 'FCA' OR IncoTerm1 = 'FOB' OR IncoTerm1 = 'EXW'. "Inco Terms FCA, FOB or EXW
ScheduleDate = ScheduleLineDate + 10.
katr3 = '01'. "
ScheduleDate = ScheduleLineDate + 7.
katr4 = '01'.
ScheduleDate = ScheduleLineDate + 5.
ELSEIF ShippingType = '22' ShippingType = '23' OR ShippingType = '24'. "DG Shipment
ScheduleDate = ScheduleLineDate + 5.
ELSE.
ScheduleDate = ScheduleLineDate + 2
ENDIF.

ELSEIF DistributionChannel = '20' OR DistributionChannel = '40' OR DistributionChannel = '60' OR DistributionChannel = '70' . "Only for Domestic
ScheduleDate = ScheduleLineDate + 2.
ENDIF.

Joseph_BERTHE
Active Contributor
0 Kudos

Hello,

No formatter is needed for your case.

If your data is stored I to an OData model, then when you do a getProperty() it returns a Date object. With javascy it will easy to add 2 days.

Then, if you want to show it in the view, you have to specify the type in the XML binding. Look at the answer of this post : https://answers.sap.com/questions/11878924/sapui5-xml-view-date-format.html

Regards,

Joseph

former_member190655
Participant
0 Kudos

You should be able to use a formatter function, as mentioned above. Add parts to your .formatter function in xml view and pass the required fields (e.g. distribution channel, shipping type) and then elaborate your formatter function to add these conditions.

<Text text="{
   part: [
    '/Timestamp', 
    '/DistChannel',
    '....'
   ], 
   formatter: '.formatter.date'
}"/>

date : function(date, field1, field2 ...){
    <Write your conditions here..>
    return strOutputDate; 
}

Hope you can work with this information.

0 Kudos

Thank you