3

I have got a timestamp that consists of date and time, something like "YYYYMMddhhmmss" and I want to display it as a datetime in the Fiori frontend like "Month dd, YYYY hh:mm PM" and enable the auto DateTimePicker.

While there are the tstmp_to_dats and tstmp_to_tims functions available in a CDS view that work fine for individual dates or times I couldn't figure out how to create a DateTime. What is the correct way?

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
Stefan Blamberg
  • 816
  • 9
  • 24

1 Answers1

2

the correct way is to format the datetime in the Fiori stack. Specify valueFormat and displayFormat of DateTimePicker.

<DateTimePicker value="20170909103032" valueFormat="yyyyMMddHHmmss" displayFormat="MM dd, yyyy HH:mm a" />

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <script id="sap-ui-bootstrap" type="text/javascript" src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" data-sap-ui-libs="sap.m" data-sap-ui-theme="sap_belize" data-sap-ui-xx-bindingSyntax="complex">
    </script>

    <script id="view1" type="sapui5/xmlview">
        <mvc:View xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core">
          <DateTimePicker value="20170909103032" valueFormat="yyyyMMddHHmmss" displayFormat="MM dd, yyyy HH:mm a" />
        </mvc:View>
    </script>
    <script>
        var myView = sap.ui.xmlview({
            viewContent: jQuery('#view1').html()
        }); // accessing the HTML inside the script tag above


        myView.placeAt('content');
    </script>

</head>

<body id='content' class='sapUiBody'>
</body>

</html>
Haojie
  • 5,665
  • 1
  • 15
  • 14
  • 1
    Is there any way to use this DateTimePicker in the Smart Filter Bar of my List View Application? Got the DateTime itself to work by setting its type to DateTime but there is still no DateTimePicker in the filter bar – Stefan Blamberg Sep 08 '17 at 11:38
  • I was able to use this in a custom SmartFilterBar extension, thank you – Stefan Blamberg Sep 08 '17 at 13:25