cancel
Showing results for 
Search instead for 
Did you mean: 

sapui5 date problem with dd/MM/yyyy format

former_member202213
Participant

Hi everyone,

i'm using sapui5 version 1.52.

i'm facing the following issue when using vizframe :

graph type is timeseries_stacked_column

i'm using a local model containing for example :

{
"Detail": [{
"Offre": "AssureEnergie",
"Semaine": "Semaine 5",
"Day": "29/03/2019",
"Nombre": 0
}, {
"Offre": "AssureEnergie",
"Semaine": "Semaine 5",
"Day": "28/03/2019",
"Nombre": 0
}, {

in order to display correctly date in the graph, here is my field in the xlm view :

<viz.data:DimensionDefinition name="Day" value="{path: 'ModelData>Day', formatter: '.formatDate'}" displayValue="{path: 'ModelData>Day', Formatter: '.formatDate'}" dataType="date"/>

in the controller, function formatDate is like this :

		formatDate: function (val) {
			if (val) {
				jQuery.sap.require("sap.ui.core.format.DateFormat");
				var oDateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({
					source: {
						pattern: "dd/MM/yyyy"
					},
					pattern: "yyyy-MM-dd HH:mm:ss"
				});
				return oDateFormat.format(new Date(val));
			}
		}

but something is wrong. if I use the code like this, 01/03 and 02/03 are displayed wrong :

instead it display 03/01 and 03/02.

I figured out that treatment seems to treat date like american ones that is to say MM/dd/yyyy instead of dd/MM/yyyy.

that's why I tried another pattern for output :

yyyy-MM-dd HH:mm:ss

this time, 01/03 and 02/03 are correct... but now after 12/03 it doesn't work... probably due to the same format as 13/03 is interpreted as 03/13 instead and [50061] - Le format de certaines dates n'est pas correct message is displayed...

is there a way to work with dd/MM/yyyy easily ? if not I've two other possibilities :

- modifying my file to use american dates as input

- modifying my file to simulate return from odata service and then using ms date/time format like \/Date(1550188800000)\/

what do you think ?

Accepted Solutions (1)

Accepted Solutions (1)

former_member196805
Contributor
0 Kudos

Hello,

One simple way to verify the date is to implement new Date("28/03/2019"). This is a generic function to browser. If it returns invalid, vizFrame would not be able to plot the date.

There are various of Date valid format. For example 2019/03/28, 2019-03-28, 1553702400000 etc.

former_member202213
Participant
0 Kudos

Ok thanks Chapman, in fact new Date("28/03/2019") returns invalid. it means that this format can't be used in vizFrame.

I thought that it was the function oDateFormat.format in my case which didn't work.

Answers (0)