An object that represents a moment in time.

Syntax

[<oRef> =] new Date( )

or

[<oRef> =] new Date(<date expC>)

or

[<oRef> =] new Date(<msec expN>)

or

[<oRef> =] new Date(<year expN>, <month expN>, <day expN>
 [, <hours expN> , <minutes expN> , <seconds expN>])

or

[<oRef> =] new Date(<year expN>, <month expN>, <day expN>
 [, <hours expN> , <minutes expN> , <seconds expN>, <timez expC>])

<oRef>

A variable or property in which you want to store a reference to the newly created Date object.

<date expC>

A string representing a date and time.

<msec expN>

The number of milliseconds since January 1, 1970 00:00:00 GMT. Negative values can be used for dates before 1970.

<year expN>

The year.

<month expN>

A number representing the month, between 0 and 11: zero for January, one for February, and so on, up to 11 for December.

<day expN>

The day of the month, from 1 to 31.

<hours expN>

The hours portion of the time, from 1 to 24.

<minutes expN>

The minutes portion of the time, from 1 to 60.

<seconds expN>

The seconds portion of the time, from 1 to 60.

<timez expC>

A Time Zone (GMT, EST, CST, MST or PST)

Properties

The following tables list the properties and methods of the Date class. (No events are associated with this class.).

Property

Default

Description

baseClassName

DATE

Identifies the object as an instance of the Date class

className

(DATE)

Identifies the object as an instance of a custom class. When no custom class exists, defaults to baseClassName

date

 

The day of the month

day

 

The day of the week, from 0 to 6: 0=Sunday, 6=Saturday

hour

 

The hour component of time (9:18:34)

minute

 

The minute component of time (9:18:34)

month

 

The month of the year, from 0 to 11: 0=January, 11=December

second

 

The seconds component of time (9:18:34)

year

 

The year of the date

 

Method

Parameters

Description

getDate( )

 

Returns day of month

getDay( )

 

Returns day of week

getHours( )

 

Returns hours portion of time

getMinutes( )

 

Returns minutes portion of time

getMonth( )

 

Returns month of year

getSeconds( )

 

Returns seconds portion of time

getTime( )

 

Returns date/time equivalent

getTimezoneOffset( )

 

Returns time zone offset for current locale

getYear( )

 

Returns year of date

parse( )

<date expC>

Calculates time equivalent for date string

setDate( )

<expN>

Sets day of month

setHours( )

<expN>

Sets hours portion of time

setMinutes( )

<expN>

Sets minutes portion of time

setMonth( )

<expN>

Sets month of year

setSeconds( )

<expN>

Sets seconds portion of time

setTime( )

<expN>

Sets date/time

setYear( )

<expN>

Sets year of date

toGMTString( )

 

Converts date to string, using Internet (GMT) conventions

toLocaleString( )

 

Converts date to string, using locale conventions

toString( )

 

Converts date to string, using standard JavaScript conventions

UTC( )

<year expN>,
<month expN>,
<day expN>,
[<hours expN>,
<minutes expN>,
<seconds expN>]

Calculates time equivalent of date parameters

Description

A Date object represents both a date and time.

There are four ways to create a new Date object:

When called with no parameters, the Date object contains the current system date and time.

You can pass a string containing a date and optionally a time. Once a time parameter has been specified, the time zone parameter may also be included. Lacking a time zone parameter, dBASE Plus defaults to the current locale.

You can pass a number representing the number of milliseconds since January 1, 1970, 00:00:00 GMT. Use a negative number for dates before 1970.

You can pass numeric parameters for each component of the date, and optionally each component of the time.

If you specify a date but don’t specify hours, minutes, or seconds, they are set to zero. When passing a string, the <date expC> can be in a variety of formats, with or without the time, as shown in the following examples:

d1 = new Date( "Jan 5 1996" ) // month, day, year

d2 = new Date( "18 Dec 1994 15:34" ) // day, month, year, and time

d3 = new Date( "1987 Nov 4 9:18:34" ) // year, month, day, and time with seconds

d4 = new Date( "1987 Nov 4 9:18:34 PST" ) // year, month, day, time with seconds, and time zone

You may spell out the month or abbreviate it, down to the first three letters; for example, "April", "Apri", or "Apr". For consistency and because of the three-letter month of May, you should either always spell it out completely or use the first three letters.

Date objects have an inherent value. The format of the date is platform-dependent; in dBASE Plus, the format is the same as using the toLocaleString( ) method. Use the toGMTString( ), toLocaleString( ), and toString( ) methods to format the Date objects, or create your own. Date objects will automatically type-convert into strings, using the inherent format.

In dBASE Plus, every Date object has a separate property for each date and time component. You may read or write to these properties directly (except for the day property, which is read-only), or use the equivalent method. For example, assigning a value to the minute property has the same effect as calling the setMinutes( ) method with the value as the parameter.

Note

While using values outside a date component's specified range does not produce an error message, they may produce unintended results. In the following example, an inadvertant minus sign before the hours component actually rolls the clock back:

d=new date(01,05,13,23,20,30)

?dtodt(d)

06/13/2001 11:20:30 PM

d=new date(01,05,13,-23,20,30)

?dtodt(d)

06/12/2001 01:20:30 AM

Change the month to 12 and watch the result jump to:

01/12/2002 01:20:30 AM

To avoid such scenarios, it is recommended that date component values fall within their stated range.

You should also aquaint yourself with the affect "rollover" will have on your date components. With the exception of the month component, "rollover" occurs whenever you use the highest number in a range. For example, using 60 for the seconds value will cause the minutes value to increase by 1, 60 minutes rollsovers to the next hour, and so on.