Date manipulation in Javascript is really easy. If you want to add a day to a date, it would be date.setDate(date.getDate() + 1)
, and subtracting works in the same fashion: date.setDate(date.getDate() - 1)
.
You just have to get the yyyymmdd
format as used by the date-picker back into Javascript's native date
type. As mentioned by @R.Schmitt, you could of course use any of Javascript tricks from Stackoverflow. On the other hand, the UI5 team has already built this logic for you in the DateFormat class, so it's probably neatest to leverage that.
To get from a yyyymmdd
to date
, you could use:
sap.ui.core.format.DateFormat.getDateInstance({pattern : "YYYYMMdd" }).parse(date);
To get from a date
to yyyymmdd
format, you can use:
sap.ui.core.format.DateFormat.getDateInstance({pattern : "YYYYMMdd"}).format(yyymmdd);
To see the Javascript date calcluation and UI5's DateFormat class in action, have a look at this jsbin:
http://jsbin.com/xeyiwic/1/edit?html,output