There are several functions to perform operations on dates.
The best place to look at the JavaScriptUtil API documentation, that have a complete list of functions. Here, the idea is not to replicate that information, but to give a basic understanding.
Most of the date manipulation functions use a field. Fields are represented by contants. Whenever a field is used and not informed, the default assumed is JST_FIELD_DAY.
The dateAdd and truncDate functions change a given date, according to a field.
Examples:var date = new Date(2000, 9, 1, 11, 30, 0); (Oct 1, 2000 11:30:07 - month starts with 0) dateAdd(date, 1) -> Oct 2, 2000 11:30:07 dateAdd(date, 1, JST_FIELD_MONTH) -> Nov 1, 2000 11:30:07 dateAdd(date, -1) -> Sep 30, 2000 11:30:07 truncDate(date) -> Oct 1, 2000 00:00:00 truncDate(date, JST_FIELD_HOUR) -> Oct 1, 2000 11:00:00 truncDate(date, JST_FIELD_MINUTE) -> Oct 1, 2000 11:30:00
The dateDiff function compares two dates, given a field, and returns the difference.
Examples:var date1 = new Date(2000, 9, 1); (Oct 1, 2000 - month starts with 0) var date2 = new Date(2000, 10, 1); (Nov 1, 2000 - month starts with 0) dateDiff(date1, date2) -> 31 dateDiff(date1, date2, JST_FIELD_MONTH) -> 1
The getMaxDay and getFullYear functions do not manipulate dates, but are related to them.
Examples:getMaxDay(1, 2000) -> 29 (Feb, 2000 - month starts with 0 and 200 is a leap year) getMaxDay(0, 2005) -> 31 (Jan, 2005 - month starts with 0) getFullYear(0) -> 2000 getFullYear(99) -> 1999 getFullYear(0) -> 2000
Previous: Working with arrays |
Table of Contents | Next: Retrieving and setting values on form fields and html elements |