Siebel eScript Language Reference > Siebel eScript Commands > The Date Object >

The Date Constructor in Siebel eScript


The Date constructor instantiates a new Date object.

To create a Date object that is set to the current date and time, use the new operator, as you would with any object.

Syntax A

var dateVar = new Date;

There are several ways to create a Date object that is set to a date and time. The following lines each demonstrate ways to get and set dates and times.

Syntax B

var dateVar = new Date(milliseconds);

Syntax C

var dateVar = new Date(dateString);

Syntax D

var dateVar = new Date(year, month, day);

Syntax E

var dateVar = new Date(year, month, day, hours, minutes, seconds);

Parameter
Description

milliseconds

The number of milliseconds since January 1, 1970.

dateString

A string representing a date and optional time.

year

A year. If the year is between 1950 and 2050, you may supply only the final two digits. Otherwise, four digits must be supplied. However, it's safest to always use four digits to minimize the risk of Y2K problems.

month

A month, specified as a number from 0 to 11. January is 0, and December is 11.

day

A day of the month, specified as a number from 1 to 31. The first day of a month is 1; the last is 28, 29, 30, or 31.

hours

An hour, specified as a number from 0 to 23. Midnight is 0; 11 PM is 23.

minutes

A minute, specified as a number from 0 to 59. The first minute of an hour is 0; the last is 59.

seconds

A second, specified as a number from 0 to 59. The first second of a minute is 0; the last is 59.

Returns

If a parameter is specified, a Date object representing the date specified by the parameter.

Usage

Syntax B returns a date and time represented by the number of milliseconds since midnight, January 1, 1970. This representation by milliseconds is a standard way of representing dates and times that makes it easy to calculate the amount of time between one date and another. However, the recommended technique is to convert dates to milliseconds format before doing calculations.

Syntax C accepts a string representing a date and optional time. The format of such a string contains one or more of the following fields, in any order:

month day, year hours:minutes:seconds

For example, the following string:

"October 13, 1995 13:13:15"

specifies the date, October 13, 1995, and the time, one thirteen and 15 seconds PM, which, expressed in 24-hour time, is 13:13 hours and 15 seconds. The time specification is optional; if it is included, the seconds specification is optional.

Syntax forms D and E are self-explanatory. Parameters passed to them are integers.

Example

The following line of code:

var aDate = new Date(1776, 6, 4)

creates a Date object containing the date July 4, 1776.

Siebel eScript Language Reference