Object

Date Class

A Date object stores the number of seconds since 12:00AM, January 1, 1904. Properties of a Date enable you to get and set a day value only, a date/time, or only a time.

Properties
AbbreviatedDate | LongDate | ShortTime
Day | LongTime | SQLDate
DayOfWeek | Minute | SQLDateTime
DayOfYear | Month | TotalSeconds
GMTOffset | Second | WeekOfYear
Hour | ShortDate | Year

Methods

# Notes

When you create and instantiate a Date object, it is initialized to the current date and time. If you try to set the date or date/time and the format is incorrect, REALbasic will raise an UnsupportedFormatException.

The date properties of FolderItems can be accessed via the CreationDate and ModificationDate properties of FolderItem objects. You can get the current date and time by creating a new date and reading the values of the Year, Month, Day, Hour, Minute, and Second properties.

In the following code:

Dim v as Variant
Dim d as Date
d= New Date
v=d

What is actually happening is that the Variant stores the value of the TotalSeconds property as a Double, along with the type information that it is a Date (the Variant's Type property = 7).

Although Date is a class that is subclassed from Object, VarType identifies a Date as a Date data type (Type=7) rather than an Object (Type=9).

Use the ParseDate function to convert a date string to a Date value.

The TotalSeconds property is the 'master' property that stores the date/time associated with a Date. The other property values are derived from TotalSeconds. If you change the value of the TotalSeconds property, the values of the Year, Month, Day, Hour, Minute, and Second properties change to reflect the second on which TotalSeconds occurs. Conversely, if you change any of these properties, the value of TotalSeconds changes commensurately.

The Date properties that return formatted date or time information are affected by the user's operating system settings. If you need to control the exact appearance of date/time information, the best way is to extract the information yourself and manage the formatting using String manipulation functions.

# Examples

This example creates a Date and displays the current date in a message box.

Dim d as Date
d= New Date
MsgBox d.shortdate

You can write this more compactly by instantiating the Date variable within the Dim statement, as in this example:

Dim d as New Date
MsgBox d.shortdate

This example sets a Date object to 10 February 1954.

Dim d as New Date
d.Year=1954
d.Month=2
d.Day=10
MsgBox d.ShortDate

The following example compares that date to the current date:

Dim d as New Date
Dim today as New Date
Dim i as Integer
d.Year=1954
d.Month=2
d.Day=10
i=today. Operator_Compare(d)

# See Also

Microseconds, ParseDate, Ticks, functions; FolderItem class.