Skip to Content
author's profile photo Former Member
Former Member

Calculate duration from DateTimeInput

Hi

I am using two sap.m.DateTimeInput controls for Begin and End Date of a trip. Now I want to calculate the duration of that trip based on the selected dates. The duration will be displayed on in a sap.m.Input.

Is there any possibility to start calculation and set the value in the input field after both dates have been selected by the user? Some kind of Listener?

Thank you very much

best regards,

Thomas Maier

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Jul 23, 2014 at 09:13 AM

    Hi Thomas,

    You could use a formatter function in the input field to calculate the duration:

    var oDuration = new sap.m.Input({value:{
        parts : ["/startDate", "/endDate"],
        formatter : function(date1, date2) {
            var days = (date2 - date1)/(1000*60*60*24);
            return days;
        }
    }})
    

    where startDate and endDate in this example are the properties bound to both datetimeinput controls

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 23, 2014 at 08:20 AM

    Hi Thomas,

    Use the 'change' event: SAPUI5 SDK - Demo Kit

    When one of the two is changed, I'd use javascript to calculate the difference.

    Kind regards,

    RW

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 23, 2014 at 08:42 AM

    Hi Thomas,

    You can use data binding to display the calculated value in a text field.

    Click on Testpage at the end of the page in the link below:

    Documentation/AdvancedTopics/DataBinding/CalcFields – SAPUI5 Wiki (TIP CORE User Interface)

    Read the event part on the link below:

    You will know more on how an event if fired when a text in a field has changed.

    DatePicker - SAPUI5 Demo Kit

    Regards,

    Ashvin

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.