Show TOC

sap.ui.model.type.DateLocate this document in the navigation structure

The Date data type represents a date (without time).

This type transforms a source value (given value in the model) into a formatted date string and the other way round.

The format patterns must be defined in LDML Date Format notation. For the output, the use of a style ("short, "medium", "long" or "full") instead of a pattern is preferred, as it will automatically use a locale-dependent date pattern.

Examples how a Date type can be initialized:

// The source value is given as Javascript Date object. The used output pattern depends on the locale settings (default).
var oType = new sap.ui.model.type.Date();
// The source value is given as Javascript Date object. The used output pattern is "yy-MM-dd": e.g. 09-11-27
oType = new sap.ui.model.type.Date({pattern: "yy-MM-dd"}); 
// The source value is given as string in "yyyy/MM/dd" format. The used output style is "long". The styles are language dependent.
// The following styles are possible: short, medium (default), long, full
// This usecase might be the common one.
oType = new sap.ui.model.type.Date({source: {pattern: "yyyy/MM/dd"}, style: "long"}); 
// The source value is given as string in "yyyy/MM/dd" format. The used output pattern is "EEEE, MMMM d, yyyy": e.g. Saturday, August 22, 2043
oType = new sap.ui.model.type.Date({source: {pattern: "yyyy/MM/dd"}, pattern: "EEEE, MMMM d, yyyy"}); 
// The source value is given as timestamp. The used output pattern is "dd.MM.yyyy": e.g. 22.12.2010
oType = new sap.ui.model.type.Date({source: {pattern: "timestamp"}, pattern: "dd.MM.yyyy"}); 
// The source value is given as string. The used input pattern depends on the locale settings (default). The used output pattern is "dd '|' MM '|' yyyy": e.g. 22 | 12 | 2010
oType = new sap.ui.model.type.Date({source: {}, pattern: "dd.MM.yyyy"});

The Date type supports the following validation constraints:

  • maximum (expects an date presented in the source-pattern format)
  • minimum (expects an date presented in the source-pattern format)