A Date represents a calendar date and time (for example May 27, 1993, 1:35 am). Dates are stored in an internal, platform-independent format and should not be confused with String representations of dates. Although "11/30/1982" looks like a Date, it is actually a String representation of a date and cannot be stored in a Date variable or manipulated as an OScript Date.
Variables declared to be of type Date are initially Undefined. Dates include both the calendar date and the time, but either can be manipulated independently, if needed. Therefore, there is no such thing as a Time data type. A time is considered a special case of a Date for which the day, month, and year information is ignored.
Date values can be obtained by executing a function that returns a Date value. For more information about these built-in functions, see the function syntax in the OScript Built-In Function online help. The most common functions used to generate new Date values are the functions Date.Now(), used to generate a Date value representing the current date and time, and Date.StringToDate(), used to generate a Date value corresponding to a String representation of a Date. The following example illustrates:
String stringDate = "03/23/1989" Date nowDate = Date.Now() Date thenDate = Date.StringToDate( stringDate, "%m/%d/%Y" )
In this example, the second parameter to Date.StringToDate() is a formatted String that tells the function how to interpret the supplied String. Type conversions can be performed to convert Strings to Dates (to perform Date manipulation) and to convert Dates to Strings (for display purposes) using the functions Date.StringToDate() and Date.DateToString().
Arithmetic operations can be performed on Dates to obtain a Date earlier or later than the supplied Date.
For example, you can add or subtract an Integer number of seconds to or from a Date:
Date rightNow, hourFromNow, tomorrow rightNow = Date.Now() hourFromNow = rightNow + ( 60 * 60 ) tomorrow = rightNow + ( 60 * 60 * 24 )
Or you can use the Date.DateInteger() function and the Date.TimeInteger() function to add and subtract days from Dates:
Integer laterInt Date laterDate, today today = Date.Now() laterInt = Date.DateInteger( today ) + 10 laterDate = Date.DateInteger( today, laterInt )
In this example, the laterDate value is obtained by converting the Date returned by the Date.Now() function to an Integer, adding ten days to it, and then converting it back to a Date.