Date Functions

All date related functions conforms to the standard Java date functions. Years, entered with two digits, will refer to 1900 if they are between 70 and 99 and refer to year 2000 if they are between 00 and 69.

Warning!

The Date functions cannot operate on null arguments. 

The following functions for Date described here are:

dateAdd*

The following functions adds a specified number of years, months, days, hours, minutes, seconds, or milliseconds to a date value.

void dateAddYears ( date d, int years )
void dateAddMonths ( date d, int months )
void dateAddDays ( date d, int days )
void dateAddHours ( date d , int hours)
void dateAddMinutes ( date d, int minutes )
void dateAddSeconds ( date d , int seconds)
void dateAddMilliseconds ( date d, int milliseconds )
ParameterDescription

d/years/months/days

A date/year/month/day...

Returns

Nothing

dateCreate*

The following functions creates a full date, based on current system timestamp of the host, or a given date and/or time:

date dateCreateNow()
date dateCreate ( int year, int month, int day, int hour, int minute, int second )


Creates dates where either the date or time part is set:

date dateCreateFromDate ( int year, int month, int day )
date dateCreateFromTime ( int hour, int minute, int second )
date dateCreateFromMilliseconds ( long milliseconds )

Creates a copy of a date:

date dateCreateCopy( date d )
ParameterDescription

d/year/month/day

A date/year/month/day...

Returns

A date

dateCreateNowMilliseconds

The dateCreateNowMilliseconds function returns the current date of the operating system in milliseconds of the operating system.

long dateCreateNowMilliseconds()
ParameterDescription

Returns

The current date in milliseconds

dateDiff

The dateDiff function calculates the difference in milliseconds between two dates. The return value is date1 - date2 which means that the result may be negative.

long dateDiff ( date date1, date date2 )
ParameterDescription

date1

The date to subtract from

date2

The date to subtract with

Returns

The difference in milliseconds

dateGet*

Given a date, the following functions return the year number, month number, day number (Monday=1, Tuesday=2, etc), hour (24 hour clock), minute, second, or millisecond.

int dateGetYear( date d )
int dateGetMonth( date d )
int dateGetDay( date d )
int dateGetDayOfWeek( date d )
int dateGetHours24( date d )
int dateGetMinutes( date d )
int dateGetSeconds( date d )
int dateGetMilliseconds( date d )
string dateGetTZ( date d )

Note!

The function dateGetTimeZone() is deprecated, please use dateGetTZ() instead.

For further information about time zone settings, see Database Configuration in the System Administrator's Guide.

Parameters:

ParameterDescription

d

The date to convert

Returns

Integers stating year/month/day/hour/second for all functions except dateGetTZ, which returns the time zone in the way stated by the JVM's TimeZoneID.

Example - When debugging the current time zone with dateGetTZ

The syntax used when debugging the current time zone with dateGetTZ:

debug( dateGetTZ( dateCreateNow() ) );

dateGetAsMilliseconds

Given a date, the function dateGetAsMilliseconds returns the total number of milliseconds since 1 Jan, 1970. This function is the inverse of dateCreateFromMilliseconds.

long dateGetAsMilliseconds( date d )
ParameterDescription

d

The date to examine.

Returns

The total number of milliseconds since 1 Jan, 1970.

dateGMTOffset

The dateGMTOffset function returns the number of milliseconds diverging from GMT.

long dateGMTOffset( date d )
ParameterDescription

d

The date to examine

Returns

Number of milliseconds diverging from GMT

dateHas*

Given a date the following functions return true if the date includes a date or time part.

boolean dateHasDate( date d ) boolean dateHasTime( date d )
ParameterDescription

d

The date to examine

Returns

true or false

dateInDaylightTime

Given a date, the dateInDaylightTime functions returns true if the date is a daylight-saving date.

boolean dateInDaylightTime( date d )
ParameterDescription

d

The date to examine

Returns

true or false

dateIsLeapYear

Given a date, the dateIsLeapYear function performs a leap year evaluation.

boolean dateIsLeapYear( date d )
ParameterDescription

d

The date to examine

Returns

true or false

dateNanoseconds

The dateNanoseconds function returns the operating system uptime in nanoseconds. This is mainly used to measure code execution times.

Note!

The returned value will have nanosecond precision, however not necessarily nanosecond accuracy, since it is dependent on how frequently values are updated in the operating system.

long dateNanoseconds()


ParameterDescription

Returns

The current value of the most precise available system timer in nanoseconds.

dateSet*

The following functions sets different parts of a given date:

void dateSetYear ( date d, int year )
void dateSetMonth ( date d, int month )
void dateSetDay ( date d, int day )
void dateSetHours24 ( date d , int hours)
void dateSetMinutes ( date d, int minutes )
void dateSetSeconds ( date d , int seconds)
void dateSetMilliseconds ( date d, int milliseconds )
void dateSetTZ ( date d, string timeZone )

The following functions sets the complete date or time part of a date:

void dateSetDate ( date d, int year, int month, int day )
void dateSetTime ( date d, int hour, int minute, int second)

Note!

The function dateSetTimeZone() is deprecated. Use dateSetTZ() instead.

For dateSetTimeZone(), timezone did not take effect until date was retrieved by one of the dateGet*-functions. With dateSetTZ() timezone takes effect immediately.

For further information about time zone settings, see  Database Configuration in the System Administrator's Guide.

ParameterDescription

d/year/month/day

A date/year/month/day...

Note!

The component to be set needs to represent a valid value in order not to throw an exception at a later stage. For instance; Month= 1-12, Hours=0-23, Minutes=0-59, Milliseconds=0-999.

Also, the date needs to represent a valid date. For instance February 31 is invalid.

timeZone

An optional string stating the timezone to set

Returns

Nothing