The apex.date namespace contains Oracle APEX functions related to date operations.
- Since:
- 21.2
Constants for the different date/time units used by apex.date functions.
Type:
- object
Properties:
Name | Type | Description |
---|---|---|
MILLISECOND |
string | Constant to use for milliseconds |
SECOND |
string | Constant to use for seconds |
MINUTE |
string | Constant to use for minutes |
HOUR |
string | Constant to use for hours |
DAY |
string | Constant to use for days |
WEEK |
string | Constant to use for weeks |
MONTH |
string | Constant to use for months |
YEAR |
string | Constant to use for years |
Examples
apex.date.UNIT = {
MILLISECOND: "millisecond",
SECOND: "second",
MINUTE: "minute",
HOUR: "hour",
DAY: "day",
WEEK: "week",
MONTH: "month",
YEAR: "year"
};
apex.date.add( myDate, 2, apex.date.UNIT.DAY );
apex.date.add( myDate, 1, apex.date.UNIT.YEAR );
apex.date.subtract( myDate, 30, apex.date.UNIT.MINUTE );
apex.date.subtract( myDate, 6, apex.date.UNIT.HOUR );
Return the ISO-8601 week number of the year of a given date object. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
Returns:
- Type
- number
Example
var weekNumber = apex.date.ISOWeek( myDate );
Add a certain amount of time to an existing date. This function returns the modified date object as well as altering the original object. If the given date object should not be manipulated use apex.date.clone before calling this function. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
pAmount |
number | The amount to add | ||
pUnit |
string |
<optional> |
apex.date.UNIT.MILLISECOND | The unit to use - apex.date.UNIT constant |
Returns:
- Type
- Date
Example
var myDate = new Date( "2021-06-20" );
myDate = apex.date.add( myDate, 2, apex.date.UNIT.DAY );
// myDate is now "2021-06-21"
Return the cloned instance of a given date object. This is useful when you want to do actions on a date object without altering the original object. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Description |
---|---|---|
pDate |
Date | A date object |
Returns:
- Type
- Date
Example
var myDate = new Date();
var clonedDate = apex.date.clone( myDate );
Return the day number of week of a given date object. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
Returns:
- Type
- number
Example
var weekDay = apex.date.dayOfWeek( myDate );
Return the day count of a month of a given date object. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
Returns:
- Type
- number
Example
var dayCount = apex.date.daysInMonth( myDate );
Return the end date of a day of a given date object. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
Returns:
- Type
- Date
Example
var dayEndDate = apex.date.endOfDay( myDate );
// output: "2021-JUN-29 23:59:59" (as date object)
Return a new date object for the first day a month of a given date object. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
Returns:
- Type
- Date
Example
var firstDayDate = apex.date.firstOfMonth( myDate );
// output: "2021-JUN-01" (as date object)
Return the formatted string of a date with a given (Oracle compatible) format mask. If pDate is not provided it uses the current date & time. It uses the default date format mask & locale defined in the application globalization settings.
Currently not supported Oracle specific formats are: SYEAR,SYYYY,IYYY,YEAR,IYY,SCC,TZD,TZH,TZM,TZR,AD,BC,CC,EE,FF,FX,IY,RM,TS,E,I,J,Q,X
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
pFormat |
string |
<optional> |
apex.locale.getDateFormat() | The format mask |
pLocale |
string |
<optional> |
apex.locale.getLanguage() | The locale |
Returns:
- Type
- string
Example
var dateString = apex.date.format( myDate, "YYYY-MM-DD HH24:MI" );
// output: "2021-06-29 15:30"
var dateString = apex.date.format( myDate, "Day, DD Month YYYY" );
// output: "Wednesday, 29 June 2021"
var dateString = apex.date.format( myDate, "Day, DD Month YYYY", "de" );
// output: "Mittwoch, 29 Juni 2021"
Return the day number of a year of a given date object. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
Returns:
- Type
- number
Example
var dayNumber = apex.date.getDayOfYear( myDate );
Return true if the first date object is after the second date. pUnit controls the precision of the comparison.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate1 |
Date | A date object | ||
pDate2 |
Date | A date object | ||
pUnit |
string |
<optional> |
apex.date.UNIT.MILLISECOND | The unit to use - apex.date.UNIT constant |
Returns:
- Type
- boolean
Example
var isDateAfter = apex.date.isAfter( myDate1, myDate2, apex.date.UNIT.SECOND );
Return true if the first date object is before the second date. pUnit controls the precision of the comparison.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate1 |
Date | A date object | ||
pDate2 |
Date | A date object | ||
pUnit |
string |
<optional> |
apex.date.UNIT.MILLISECOND | The unit to use - apex.date.UNIT constant |
Returns:
- Type
- boolean
Example
var isDateBefore = apex.date.isBefore( myDate1, myDate2, apex.date.UNIT.SECOND );
Return true if the first date object is between the second date and the third date. pUnit controls the precision of the comparison.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate1 |
Date | A date object | ||
pDate2 |
Date | A date object | ||
pDate3 |
Date | A date object | ||
pUnit |
string |
<optional> |
apex.date.UNIT.MILLISECOND | The unit to use - apex.date.UNIT constant |
Returns:
- Type
- boolean
Example
var isDateBetween = apex.date.isBetween( myDate1, myDate2, myDate3, apex.date.UNIT.SECOND );
Return true if a given date object is within a leap year. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
Returns:
- Type
- boolean
Example
var isLeapYear = apex.date.isLeapYear( myDate );
Return true if the first date object is the same as the second date. pUnit controls the precision of the comparison.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate1 |
Date | A date object | ||
pDate2 |
Date | A date object | ||
pUnit |
string |
<optional> |
apex.date.UNIT.MILLISECOND | The unit to use - apex.date.UNIT constant |
Returns:
- Type
- boolean
Example
var isDateSame = apex.date.isSame( myDate1, myDate2, apex.date.UNIT.SECOND );
Return true if the first date object is the same or after the second date. pUnit controls the precision of the comparison.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate1 |
Date | A date object | ||
pDate2 |
Date | A date object | ||
pUnit |
string |
<optional> |
apex.date.UNIT.MILLISECOND | The unit to use - apex.date.UNIT constant |
Returns:
- Type
- boolean
Example
var isDateSameAfter = apex.date.isSameOrAfter( myDate1, myDate2, apex.date.UNIT.SECOND );
Return true if the first date object is the same or before the second date. pUnit controls the precision of the comparison.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate1 |
Date | A date object | ||
pDate2 |
Date | A date object | ||
pUnit |
string |
<optional> |
apex.date.UNIT.MILLISECOND | The unit to use - apex.date.UNIT constant |
Returns:
- Type
- boolean
Example
var isDateSameBefore = apex.date.isSameOrBefore( myDate1, myDate2, apex.date.UNIT.SECOND );
Return true if a given object is a valid date object.
Parameters:
Name | Type | Description |
---|---|---|
pDate |
Date | A date object |
Returns:
- Type
- boolean
Example
var isDateValid = apex.date.isValid( myDate );
Return true if a given string can parse into a date object. Note: This could be browser specific dependent on the implementation of Date.parse.
Most browsers expect a string in ISO format (ISO 8601) and shorter versions of it, like "2021-06-15T14:30:00" or "2021-06-15T14:30" or "2021-06-15"
Parameters:
Name | Type | Description |
---|---|---|
pDateString |
string | A date string |
Returns:
- Type
- boolean
Example
var isDateValid = apex.date.isValidString( "2021-06-29 15:30" );
Return a new date object for the last day of a month of a given date object. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
Returns:
- Type
- Date
Example
var lastDayDate = apex.date.lastOfMonth( myDate );
// output: "2021-JUN-30" (as date object)
Return the maximum date of given date object arguments. If pDates is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDates |
date |
<optional> <repeatable> |
[new Date()] | Multiple date objects as arguments |
Returns:
- Type
- Date
Example
var maxDate = apex.date.max( myDate1, myDate2, myDate3 );
Return the minimum date of given date object arguments. If pDates is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDates |
date |
<optional> <repeatable> |
[new Date()] | Multiple date objects as arguments |
Returns:
- Type
- Date
Example
var minDate = apex.date.min( myDate1, myDate2, myDate3 );
Return the count of months between 2 date objects.
Parameters:
Name | Type | Description |
---|---|---|
pDate1 |
Date | A date object |
pDate2 |
Date | A date object |
Returns:
- Type
- number
Example
var months = apex.date.monthsBetween( myDate1, myDate2 );
Return the parsed date object of a given date string and a (Oracle compatible) format mask. It uses the default date format mask defined in the application globalization settings.
Currently not supported Oracle specific formats are: SSSSS,SYEAR,SYYYY,IYYY,YEAR,IYY,SCC,TZD,TZH,TZM,TZR,AD,BC,CC,EE,FF,FX,IW,IY,RM,TS,WW,E,I,J,Q,W,X
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDateString |
string | A formatted date string | ||
pFormat |
string |
<optional> |
apex.locale.getDateFormat() | The format mask |
Returns:
- Type
- Date
Example
var date = apex.date.parse( "2021-06-29 15:30", "YYYY-MM-DD HH24:MI" );
var date = apex.date.parse( "2021-JUN-29 08:30 am", "YYYY-MON-DD HH12:MI AM" );
Return the seconds past midnight of day of a given date object.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
Returns:
- Type
- number
Example
var seconds = apex.date.secondsPastMidnight( myDate );
Set the day number of a year of a given date object. If the given date object should not be manipulated use apex.date.clone before calling this function. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
pDay |
number | The day number |
Returns:
- Type
- Date
Example
var myDate = new Date();
apex.date.setDayOfYear( myDate, 126 );
Return the relative date in words of a given date object This is the client side counterpart of the PL/SQL function APEX_UTIL.GET_SINCE. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
string |
<optional> |
new Date() | A date object |
pShort |
boolean |
<optional> |
false | Whether to return a short version of relative date |
Returns:
- Type
- string
Example
var sinceString = apex.date.since( myDate );
// output: "2 days from now" or "30 minutes ago"
var sinceString = apex.date.since( myDate, true );
// output: "In 1.1y" or "30m"
Return the start date of a day of a given date object. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
Returns:
- Type
- Date
Example
var dayStartDate = apex.date.startOfDay( myDate );
// output: "2021-JUN-29 24:00:00" (as date object)
Subtract a certain amount of time of an existing date. This function returns the modified date object as well as altering the original object. If the given date object should not be manipulated use apex.date.clone before calling this function. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
pAmount |
number | The amount to subtract | ||
pUnit |
string |
<optional> |
apex.date.UNIT.MILLISECOND | The unit to use - apex.date.UNIT constant |
Returns:
- Type
- Date
Example
var myDate = new Date( "2021-06-20" )
myDate = apex.date.subtract( myDate, 2, apex.date.UNIT.DAY );
// myDate is now "2021-06-19"
Return the ISO format string (ISO 8601) without timezone information of a given date object. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
Returns:
- Type
- string
Example
var isoFormat = apex.date.toISOString( myDate );
// output: "2021-06-15T14:30:00"
Return the week number of a month of a given date object. If pDate is not provided it uses the current date & time.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pDate |
Date |
<optional> |
new Date() | A date object |
Returns:
- Type
- number
Example
var weekNumber = apex.date.weekOfMonth( myDate );