Chapter 3 DynaScript Predefined Objects


Date methods

The Date object has these methods:

getDate method

Syntax

Date.getDate( )

Description

Returns the day of the month in local time.

Return

Integer.

Example

This example displays the numeric day of the month:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( myDate.getDate() );
-->

getDay method

Syntax

Date.getDay( )

Description

Returns the day of the week in local time.

Return

An integer between 0 and 6.

Example

This example displays the day of the week, which in this case is 1 (Monday):

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "week day: " + myDate.getDay() );
-->

getFullYear method

Syntax

Date.getFullYear( )

Description

Returns the year in local time.

Return

An absolute number representing the full year.

Example

This example displays the full year of the Date object:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "year: " + myDate.getFullYear() );
-->

getHours method

Syntax

Date.getHours( )

Description

Returns the hours value in local time.

Return

Integer between 0 and 23.

Example

This example displays the numeric value of the Date objects hour:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "hour: " + myDate.getHours() );
-->

getMilliseconds method

Syntax

Date.getMilliseconds( )

Description

Returns the milliseconds value in local time.

Return

Integer from 0 to 999.

Example

This example displays the number of milliseconds in the Date object:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "Milliseconds: " + myDate.getMilliseconds() );
-->

getMinutes method

Syntax

Date.getMinutes( )

Description

Returns the minutes value in local time.

Return

Integer between 0 and 59.

Example

This example displays the number of minutes in the Date object:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "Minutes: " + myDate.getMinutes() );
-->

getMonth method

Syntax

Date.getMonth( )

Description

Returns the month value in local time.

Return

Integer between 0 and 11. 0 is equal to January.

Example

This example displays the month value of the Date object:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "Month: " + myDate.getMonth() );
-->

getSeconds method

Syntax

Date.getSeconds( )

Description

Returns the seconds value.

Return

Integer between 0 and 59.

Example

This example displays the seconds value of the Date object:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "Seconds: " + myDate.getSeconds() );
-->

getTime method

Syntax

Date.getTime( )

Description

Returns the time value in local time. This value represents the number of milliseconds between the specified time and midnight, January 1, 1970. Negative numbers indicate dates prior to midnight, January 1, 1970.

Return

Integer.

Example

This example displays the number of milliseconds that have elapsed since January 1, 1970 and the Date object:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "Time: " + myDate.getTime() );
-->

getTimezoneOffset method

Syntax

Date.getTimezoneOffset( )

Description

Returns the difference in minutes, between the local time and the Universal Coordinated Time.

Return

Integer.

Example

This example displays the number of minutes between the local time and the Universal Coordinated Time:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "Time zone offset: " + myDate.getTimezoneOffset() );
-->

getUTCDate method

Syntax

Date.getUTCDate( )

Description

Returns the numeric date of the Date object, in Universal Coordinated Time.

Return

Integer between 1 and 31 that represents the date value in the Date object.

Example

This example displays the numeric date of the date object in Universal Coordinated Time:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30" );
myUTCDate = myDate.getUTCDate();
document.WriteLn( "UTC date: " + myUTCDate );
-->

getUTCDay method

Syntax

Date.getUTCDay( )

Description

Returns the day of the week from the Date object, in Universal Coordinated Time.

Return

Integer between 0 and 6 representing the day of the week.

Example

This example displays the day of the week in UTC time:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "UTC date: " + myDate.getUTCDay() );
-->

getUTCFullYear method

Syntax

Date.getUTCFullYear( )

Description

Returns the full year from the Date object, in Universal Coordinated Time.

Return

Integer.

Example

This example displays the full year in UTC time:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "UTC full year: " + myDate.getUTCFullYear() );
-->

getUTCHours method

Syntax

Date.getUTCHours( )

Description

Returns the hours from the Date object, in Universal Coordinated Time.

Return

Integer 0 to 23.

Example

This example returns the hours in UTC time:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30" );
document.WriteLn( "UTC hours: " + myDate.getUTCHours() );
-->

getUTCMilliseconds method

Syntax

Date.getUTCMilliseconds( )

Description

Returns the milliseconds value in a Date object using Universal Coordinated Time.

Return

Integer.

Example

This example displays the number of milliseconds being held in the Date object in UTC time:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "UTC milliseconds: " + myDate.getUTCMilliseconds() );
-->

getUTCMinutes method

Syntax

Date.getUTCMinutes( )

Description

Returns the minutes value in a Date object, using Universal Coordinated Time.

Return

Integer between 0 and 59.

Example

This example displays the number of minutes being held in the Date object in UTC time:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "UTC minutes: " + myDate.getUTCMinutes() );
-->

getUTCMonth method

Syntax

Date.getUTCMonth( )

Description

Returns the month value in a Date object, using Universal Coordinated Time.

Return

Integer between 0 and 11.

Example

This example displays the UTC month of the Date object:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "UTC month: " + myDate.getUTCMonth() );
-->

getUTCSeconds method

Syntax

Date.getUTCSeconds( )

Description

Returns the seconds value in a Date object, using Universal Coordinated Time.

Return

Integer between 0 and 59.

Example

This example displays the number of seconds (in UTC time) in the Date object:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "UTC seconds: " + myDate.getUTCSeconds() );
-->

getYear method

Syntax

Date.getYear( )

Description

Returns the year value in a Date object in local time. Use the getFullYear method instead, to avoid Y2K problems.

Return

Integer.

Example

This example displays the year of the Date object:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Year: " + myDate.getYear() );
-->

parse method

Syntax

Date.parse( string )

Description

Parses a string containing a date and returns the number of milliseconds between the date and midnight of January 1, 1970. The string may be in the following formats:

Use the parse method with the built-in Date object as shown in this example. The parse method does not work with instances of the Date object.

Return

Integer (milliseconds).

Example

This example returns the number of milliseconds between the date string and January 1, 1970:

<!--SCRIPT 
dateString = "March 11, 1996"
document.WriteLn( Date.parse(dateString) );
-->

setDate method

Syntax

Date.setDate( numDate )

Description

Sets the numeric day of the month of the Date object. numDate is a numeric value equal to the numeric date. If a value is greater than its range, the other values will be modified accordingly. For example, if the current date was January 3 and setDate was set to 33, the month would change to February and the date would be set to 2.

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example changes the numeric date of the Date object to the 23rd:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Date: " + myDate.getDate() );
myDate.setDate( "23" );
document.WriteLn( "Date: " + myDate.getDate() );
-->

setFullYear method

Syntax

Date.setFullYear( numYear [, numMonth, [numDate]] )

Description

Sets the year value in the Date object. The range of years supported is approximately 285616 years on either side of 1970. The parameters are:

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example changes the year of the Date object to 1999:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Year: " + myDate.getFullYear() );
myDate.setFullYear( "99" );
document.WriteLn( "Year: " + myDate.getFullYear() );
-->

setHours method

Syntax

Date.setHours( numHours [, numMin, [numSec, [numMilli]]] )

Description

Sets the hours value in the Date object using local time. If a value is greater than its range, the value will be modified accordingly. For example, the numHours value of 30 would actually be equal to 6:00:00 (a day plus 6 hours). The parameters are:

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example changes the time of the Date object:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Hours: " + myDate.getHours() );
myDate.setHours( "12", "15", "01" );
document.WriteLn( "Hours: " + myDate.getHours() );
-->

setMilliseconds method

Syntax

Date.setMilliseconds( numMilli )

Description

Sets the milliseconds value in the Date object. numMilli is the numeric value equal to the millisecond value you wish to set. If the value is greater than 999, the number of seconds is increased as required. For example, 1020 milliseconds would be equal to one second and 21 milliseconds.

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example changes the number of milliseconds in the Date object:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Hours: " + myDate.getMilliseconds() );
myDate.setMilliseconds( "89" );
document.WriteLn( "Hours: " + myDate.getMilliseconds() );
-->

setMinutes method

Syntax

Date.setMinutes( numMin [, numSec, numMilli] )

Description

Sets the minutes value in the Date object. If a value is greater than its range, the value will be modified accordingly. For example, the value of 80 minutes would actually be equal to 1:20:00. The parameters are:

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example changes the value of the minutes in the Date object. Because the number of minutes is larger than 59, the and the hour value will be incremented by one (to 9), and the minute value is changed accordingly.

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Old Minutes: " + myDate.getMinutes() );
myDate.setMinutes( "89" );
document.WriteLn( "New hours: " + myDate.getHours() );
document.WriteLn( "New minutes: " + myDate.getMinutes() );
-->

The output from this example is:

Old Minutes: 30
New hours: 9
New minutes: 29

setMonth method

Syntax

Date.setMonth( numMonth [, dateVal] )

Description

Sets the month value for the Date object. January is equal to 0. If the value of a parameter exceeds its range, other parameters will be changed accordingly. The parameters are:

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example changes the month value of the Date object to March:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Old month: " + myDate.getMonth() );
myDate.setMonth( "02" );
document.WriteLn( "New month: " + myDate.getMonth() );
-->

setSeconds method

Syntax

Date.setSeconds( numSec [, numMilli] )

Description

Sets the seconds value in the Date object using local time. If the value of a parameter exceeds its range, other parameters are changed accordingly. The parameters are:

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example changes the value of the seconds in the Date object:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
myDate.setSeconds( "58" );
document.WriteLn( "Seconds: " + myDate.getSeconds() );
-->

setTime method

Syntax

Date.setTime( numMilli )

Description

Sets the date and time value in the Date object. numMilli is an integer that represents the number of milliseconds that have elapsed since midnight, January 1, 1970 GMT. A negative number indicates a date earlier than January 1, 1970. PowerDynamo supports a range between -2147483649 and 2147483647. To set dates that are beyond this range, use a floating point.

Using setTime to set the date and time of a Date object is time zone independent.

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example sets the date and time of a date object with the setTime method:

<!--SCRIPT 
myDate = new Date( );
myDate.setTime( "5324654" );
document.WriteLn( "Year: " + myDate.getUTCFullYear() );
document.WriteLn( "Month: " + myDate.getUTCMonth() );
document.WriteLn( "Date: " + myDate.getUTCDate() );
document.WriteLn( "Hours: " + myDate.getUTCHours() );
document.WriteLn( "Minutes: " + myDate.getUTCMinutes() );
-->

The output from this example is:

Year: 1970
Month: 0
Date: 1
Hours: 1
Minutes: 28

setUTCDate method

Syntax

Date.setUTCDate( numDate )

Description

Sets the numeric date in the Date object using Universal Coordinated Time. numDate represents the date that is to be set.

If the value of a parameter exceeds its range, other parameters will be changed accordingly. For example, if the current date was January 12 and SetUTCDate(33) was given, the new month and date would be February 2.

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example changes the date of the Date object. Because the new date value exceeds the number of days in the month of February, the month value is incremented by one, and the date is changed accordingly:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( "Old date: " + myDate.getUTCDate() );
document.WriteLn( "Old month: " + myDate.getUTCMonth() );
myDate.setUTCDate( "45" );
document.WriteLn( "New date: " + myDate.getUTCDate() );
document.WriteLn( "New month: " + myDate.getUTCMonth() );
-->

This example displays this output:

Old date: 11
Old month: 1
New date: 17
New month: 2

setUTCFullYear method

Syntax

Date.setUTCFullYear( numYear [, numMonth, [numDate]] )

Description

Sets the value of the year in the Date object using Universal Coordinated Time. The range of years supported is approximately 285616 years on either side of 1970. The parameters are

If the value of a parameter exceeds its range, other parameters are changed accordingly. For example if the current date value was January 1, 1983 and the numDate parameter given is 32, the date changes to February 1, 1983.

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example changes the year of the Date object and displays the new value:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
myDate.setUTCFullYear( "78" );
document.WriteLn( "New date: " + myDate.getUTCFullYear() );
-->

setUTCHours method

Syntax

Date.setUTCHours( numHours [, numMin, [numSec, [numMilli]]] )

Description

Sets the hours value in the Date object using Universal Coordinated Time. If a value is greater than its range, the value will be modified accordingly. For example, the numHours value of 30 would actually be equal to 6:00:00 (a day plus six hours). The parameters are:

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example changes the hours value of the Date object and displays the new value:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
myDate.setUTCHours( "9" );
document.WriteLn( "New hour: " + myDate.getUTCHours() );
-->

setUTCMilliseconds method

Syntax

Date.setUTCMilliseconds( numMilli )

Description

Sets the milliseconds value for the Date object. If the number of milliseconds is greater than 999 or a negative number, the stored number of seconds reflects this accordingly. For example, 1020 milliseconds is equal to one second and 21 milliseconds.

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example changes the milliseconds value of the Date object and displays the new value:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
myDate.setUTCMilliseconds( "12" );
document.WriteLn( "New milliseconds: " + myDate.getUTCMilliseconds() );
-->

setUTCMinutes method

Syntax

Date.setUTCMinutes( numMin [numSec, numMilli] )

Description

Sets the minutes value in the Date object using Universal Coordinated Time. If a value is greater than its range, the value is modified accordingly. For example, the value of 80 minutes would actually be equal to 1:20:00. The parameters are:

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example changes the minute value of the Date object and displays the new value:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
myDate.setUTCMinutes( "45" );
document.WriteLn( "New minutes: " + myDate.getUTCMinutes() );
-->

setUTCMonth method

Syntax

Date.setUTCMonth( numMonth [, dateVal] )

Description

Sets the month value for the Date object. January is equal to 0. If the value of a parameter exceeds its range, other parameters are changed accordingly. The parameters are:

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example changes the month value of the Date object and displays the new value:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
myDate.setUTCMonth( "6" );
document.WriteLn( "New month: " + myDate.getUTCMonth() );
-->

setUTCSeconds method

Syntax

Date.setUTCSeconds( numSec [, numMilli] )

Description

Sets the seconds value in the Date object using Universal Coordinated Time. If the value of a parameter exceeds its range, other parameters are changed accordingly. The parameters are:

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

Example

This example changes the second value of the Date object and displays the new value:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
myDate.setUTCSeconds( "00" );
document.WriteLn( "New seconds: " + myDate.getUTCSeconds() );
-->

setYear method

Syntax

Date.setYear( numYear )

Description

Sets the year value in the Date object. This method is currently maintained only for backward compatibility. Use the setFullYear method instead.

Return

Integer. The number of milliseconds since midnight, January 1, 1970.

toGMTString method

Syntax

Date.toGMTString( )

Description

Returns a date as a string in Greenwich Mean Time. This method is currently supported only for backward compatibility. Use the toUTCString instead.

Return

String.

toLocaleString method

Syntax

Date.toLocaleString( )

Description

Returns a date as a string using the current locale.

Return

String. The format of this string changes depending on the locale. For example, the date January 10, 1998 is represented by:

Example

This example displays the value of the Date object in local time:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( myDate.toLocaleString() );
-->

The output from this example is:

Wed, 11 Feb 1998 08:30:11

toString method

Syntax

Date.toString( )

Description

Returns the date as a string in a convenient, readable format in local time.

Return

String.

Example

This example displays the value of the Date object in local time:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( myDate.toString() );
-->

The output from this example is:

Wed, 11 Feb 1998 08:30:11

toUTCString method

Syntax

Date.toUTCString( )

Description

Returns a date as a string in Universal Coordinated Time.

Return

String.

Example

This example displays the value of the Date object in Universal Coordinated Time:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( myDate.toUTCString() );
-->

The output from this example is:

Wed, 11 Feb 1998 13:30:11 UTC

valueOf method

Syntax

Date.valueOf( )

Description

Returns the time value in local time. This value represents the number of milliseconds between the specified time and midnight, January 1, 1970. Negative numbers indicate dates prior to midnight, January 1, 1970.

Return

Integer.

Example

This example displays the number of milliseconds that have elapsed since January 1, 1970 and the value of the Date object:

<!--SCRIPT 
myDate = new Date( "98", "01", "11", "8","30", "11", "35" );
document.WriteLn( myDate.valueOf() );
-->

 


Copyright © 1999 Sybase, Inc. All rights reserved.