<div class="meta" robots="noindex">

</div>

Class

# Date

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2019r2. Please use `DateTime</api/data_types/datetime>` as a replacement.

</div>

## Description

A <span class="title-ref">Date</span> object stores the number of seconds since 12:00 AM, January 1, 1904, i.e., "1904-01-01 00:00:00". Properties of a <span class="title-ref">Date</span> enable you to get and set a day value only, a date/time, or only a time.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                    | Type                               | Read-Only | Shared |
|-----------------------------------------|------------------------------------|-----------|--------|
| `AbbreviatedDate<date.abbreviateddate>` | `String</api/data_types/string>`   | ✓         |        |
| `Day<date.day>`                         | `Integer</api/data_types/integer>` |           |        |
| `DayOfWeek<date.dayofweek>`             | `Integer</api/data_types/integer>` | ✓         |        |
| `DayOfYear<date.dayofyear>`             | `Integer</api/data_types/integer>` | ✓         |        |
| `GMTOffset<date.gmtoffset>`             | `Double</api/data_types/double>`   |           |        |
| `Hour<date.hour>`                       | `Integer</api/data_types/integer>` |           |        |
| `LongDate<date.longdate>`               | `String</api/data_types/string>`   | ✓         |        |
| `LongTime<date.longtime>`               | `String</api/data_types/string>`   | ✓         |        |
| `Minute<date.minute>`                   | `Integer</api/data_types/integer>` |           |        |
| `Month<date.month>`                     | `Integer</api/data_types/integer>` |           |        |
| `Second<date.second>`                   | `Integer</api/data_types/integer>` |           |        |
| `ShortDate<date.shortdate>`             | `String</api/data_types/string>`   | ✓         |        |
| `ShortTime<date.shorttime>`             | `String</api/data_types/string>`   | ✓         |        |
| `SQLDate<date.sqldate>`                 | `String</api/data_types/string>`   |           |        |
| `SQLDateTime<date.sqldatetime>`         | `String</api/data_types/string>`   |           |        |
| `TotalSeconds<date.totalseconds>`       | `Double</api/data_types/double>`   |           |        |
| `WeekOfYear<date.weekofyear>`           | `Integer</api/data_types/integer>` | ✓         |        |
| `Year<date.year>`                       | `Integer</api/data_types/integer>` |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                             | Parameters                                                                                                                                                                                                                                                                                                                                    | Returns | Shared |
|----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|--------|
| `Constructor<date.constructor0>` |                                                                                                                                                                                                                                                                                                                                               |         |        |
| `Constructor<date.constructor1>` | CopyDate As Date                                                                                                                                                                                                                                                                                                                              |         |        |
| `Constructor<date.constructor2>` | Year As `Integer</api/data_types/integer>`, Month As `Integer</api/data_types/integer>` = 1, Day As `Integer</api/data_types/integer>` = 1, hour As `Integer</api/data_types/integer>` = 0, minute As `Integer</api/data_types/integer>` = 0, second As `Integer</api/data_types/integer>` = 0                                                |         |        |
| `Constructor<date.constructor3>` | Year As `Integer</api/data_types/integer>`, Month As `Integer</api/data_types/integer>` = 1, Day As `Integer</api/data_types/integer>` = 1, hour As `Integer</api/data_types/integer>` = 0, minute As `Integer</api/data_types/integer>` = 0, second As `Integer</api/data_types/integer>` = 0, GMTOffset As `Double</api/data_types/double>` |         |        |

## Property descriptions

<div id="date.abbreviateddate">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.AbbreviatedDate

**AbbreviatedDate** As `String</api/data_types/string>`

Reports the <span class="title-ref">Date</span> in the user's abbreviated <span class="title-ref">Date</span> format as a `String</api/data_types/string>` based on the user's locale and formatting even if the user's locale is a Unicode-only locale.

This property is read-only.

Changing the user's system settings for this format will change the format that AbbreviatedDate uses. On Mac, the AbbreviatedDate property is controlled by the Medium format setting. On Windows, it is an abbreviated version of the Long <span class="title-ref">Date</span> format.

The following code displays the current <span class="title-ref">Date</span> in the AbbreviatedDate format.

``` xojo
Dim d As New Date
Label1.Text = d.AbbreviatedDate
```

<div id="date.day">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.Day

**Day** As `Integer</api/data_types/integer>`

The day number of the <span class="title-ref">Date</span>.

The following displays the current day:

``` xojo
Var d As Date = New Date
Label1.Text = d.Day.ToString
```

<div id="date.dayofweek">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.DayOfWeek

**DayOfWeek** As `Integer</api/data_types/integer>`

The day of the week as an integer: 1=Sunday, 7=Saturday.

This property is read-only.

The following displays the current day of the week.

``` xojo
Var d As Date = New Date
Label1.Text = d.DayOfWeek.ToString
```

<div id="date.dayofyear">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.DayOfYear

**DayOfYear** As `Integer</api/data_types/integer>`

The number days into the year that the <span class="title-ref">Date</span> falls on.

This property is read-only.

The following code displays the current day of the year.

``` xojo
Var d As Date = New Date
Label1.Text = d.DayOfYear.ToString
```

<div id="date.gmtoffset">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.GMTOffset

**GMTOffset** As `Double</api/data_types/double>`

The difference between local time and Greenwich Mean Time (aka UTC) in hours. Changing the GMTOffset changes the time stored by the <span class="title-ref">Date</span> object.

The following code changes the GMT offset.

``` xojo
Dim d As New Date
d.Day = 13
d.Month = 8
d.Year = 1956
d.GMTOffset = -7  
```

<div id="date.hour">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.Hour

**Hour** As `Integer</api/data_types/integer>`

The hour number of the time portion of the <span class="title-ref">Date</span>, using a 24-hour clock.

The following example displays the current hour.

``` xojo
Var d As Date = New Date
Label1.Text = d.Hour.ToString
```

<div id="date.longdate">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.LongDate

**LongDate** As `String</api/data_types/string>`

Reports the <span class="title-ref">Date</span> in the user's long <span class="title-ref">Date</span> format as a `string</api/data_types/string>` based on the user's locale and formatting even if the user's locale is a Unicode-only locale.

This property is read-only.

For example (US default format): Wednesday, December 31, 1997. The LongDate property uses the Long format on Windows and the Full format on Mac. Changing the user's system settings for these formats changes the format that the LongDate property uses.

The following example displays the current <span class="title-ref">Date</span> in the LongDate format for the user's operating system.

``` xojo
Dim d As New Date
Label1.Text = d.LongDate
```

<div id="date.longtime">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.LongTime

**LongTime** As `String</api/data_types/string>`

Reports the <span class="title-ref">Date</span> in the user's long time format as a `string</api/data_types/string>` based on the user's locale and formatting even if the user's locale is a Unicode-only locale.

This property is read-only.

For example (US format): 2:32:40 PM.

The following example displays the current time in the LongTime format.

``` xojo
Dim d As New Date
d.GMTOffset = -7

Label1.Text = d.Longtime
```

<div id="date.minute">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.Minute

**Minute** As `Integer</api/data_types/integer>`

The minute number of the time portion of the <span class="title-ref">Date</span>.

The following code displays the current minute.

``` xojo
Var d As Date = New Date
Label1.Text = d.Minute.ToString
```

<div id="date.month">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.Month

**Month** As `Integer</api/data_types/integer>`

The month number of the <span class="title-ref">Date</span>.

The following code displays the current month:

``` xojo
Var d As Date = New Date
MonthLabel.Value = d.Month.ToString
```

<div id="date.second">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.Second

**Second** As `Integer</api/data_types/integer>`

The second number of the time portion of the <span class="title-ref">Date</span>.

The following code displays the Second property.

``` xojo
Var d As Date = New Date
Label1.Text = d.Second.ToString
```

<div id="date.shortdate">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.ShortDate

**ShortDate** As `String</api/data_types/string>`

Reports the <span class="title-ref">Date</span> in the user's short <span class="title-ref">Date</span> format as a `string</api/data_types/string>` based on the user's locale and formatting even if the user's locale is a Unicode-only locale.

This property is read-only.

For example (US format): 12/31/97. The ShortDate format uses the Short format on both Windows and Mac. Changing this format changes the format that the ShortDate property uses.

The following code displays today's <span class="title-ref">Date</span> in the ShortDate format.

``` xojo
Dim d As New Date
Label1.Text = d.ShortDate  
```

<div id="date.shorttime">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.ShortTime

**ShortTime** As `String</api/data_types/string>`

Reports the <span class="title-ref">Date</span> in the user's short time format as a `string</api/data_types/string>` based on the user's locale and formatting even if the user's locale is a Unicode-only locale.

This property is read-only.

This is an example of the short time (US format): 2:32 PM.

The following code reports the current time in the ShortTime format.

``` xojo
Dim d As New Date

Label1.Text = d.ShortTime
```

<div id="date.sqldate">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.SQLDate

**SQLDate** As `String</api/data_types/string>`

Gets and sets the <span class="title-ref">Date</span> in SQL <span class="title-ref">Date</span> format, *YYYY-MM-DD*. Passing a bad string will result in an `UnsupportedFormatException</api/exceptions/unsupportedformatexception>`.

This is an example for a SQL \`Date\`: 2008-09-03

The following code displays the SQLDate value for the current <span class="title-ref">Date</span>.

``` xojo
Var d As Date = New Date
Label1.Text = d.SQLDate
```

<div id="date.sqldatetime">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.SQLDateTime

**SQLDateTime** As `String</api/data_types/string>`

Gets and sets the <span class="title-ref">Date</span> in SQL date/time format, YYYY-MM-DD HH:MM:SS. Passing a bad string will result in an `UnsupportedFormatException</api/exceptions/unsupportedformatexception>`.

This is an example of an SQL date/time: 2008-09-03 13:39:16

The following code displays the current SQL date/time.

``` xojo
Var d As Date = New Date
Label1.Text = d.SQLDateTime
```

<div id="date.totalseconds">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.TotalSeconds

**TotalSeconds** As `Double</api/data_types/double>`

The number of seconds since 12:00AM, January 1, 1904, local time.

TotalSeconds is the "master" property from which other ways of expressing date/time are derived. A negative value of TotalSeconds indicates a Date/Time prior to January 1, 1904. Very, very large values of TotalSeconds will cause the value to be set to zero.

On Windows (due to the Windows API being used), it is not possible to go back further than 1 January 1601.

You can use TotalSeconds to calculate elapsed seconds:

``` xojo
Dim d1 As New Date
Dim startTime As Double = d1.TotalSeconds
' Do some long process
d2 = New Date
Dim endTime As Double = d2.TotalSeconds
Dim elapsedSeconds = endTime - startTime
```

<div id="date.weekofyear">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.WeekOfYear

**WeekOfYear** As `Integer</api/data_types/integer>`

The number of the week of the year the <span class="title-ref">Date</span> falls in.

This property is read-only.

The first week is numbered 1. The first week may be incomplete. If January 1 falls on a Saturday, then the next day is in week 2.

The following code displays the current week of the year.

``` xojo
Var d As Date = New Date
MessageBox("Week: " + d.WeekOfYear.ToString)
```

<div id="date.year">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.Year

**Year** As `Integer</api/data_types/integer>`

The year portion of the <span class="title-ref">Date</span>.

The following code displays the current year.

``` xojo
Var d As Date = New Date
Label1.Text = d.Year.ToString
```

## Method descriptions

<div id="date.constructor0">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.Constructor

**Constructor**

<div class="note">

<div class="title">

Note

</div>

`Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.

</div>

Sets the new <span class="title-ref">Date</span> object to be equal to the current <span class="title-ref">Date</span> (and time).

<div id="date.constructor1">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.Constructor

**Constructor**(CopyDate as Date)

<div class="note">

<div class="title">

Note

</div>

`Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.

</div>

Sets the new <span class="title-ref">Date</span> object to have the same <span class="title-ref">Date</span> information as the passed <span class="title-ref">Date</span>.

<div id="date.constructor2">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.Constructor

**Constructor**(Year as `Integer</api/data_types/integer>`, Month as `Integer</api/data_types/integer>` = 1, Day as `Integer</api/data_types/integer>` = 1, hour as `Integer</api/data_types/integer>` = 0, minute as `Integer</api/data_types/integer>` = 0, second as `Integer</api/data_types/integer>` = 0)

<div class="note">

<div class="title">

Note

</div>

`Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.

</div>

Sets the new <span class="title-ref">Date</span> object to the passed Year, Month, and Day, Hour, Minute. and Second.

<div id="date.constructor3">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Date.Constructor

**Constructor**(Year as `Integer</api/data_types/integer>`, Month as `Integer</api/data_types/integer>` = 1, Day as `Integer</api/data_types/integer>` = 1, hour as `Integer</api/data_types/integer>` = 0, minute as `Integer</api/data_types/integer>` = 0, second as `Integer</api/data_types/integer>` = 0, GMTOffset as `Double</api/data_types/double>`)

<div class="note">

<div class="title">

Note

</div>

`Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.

</div>

Sets the new <span class="title-ref">Date</span> object to the passed Year, Month, Day, Hour, Minute, Second, and GMTOffset. Requires setting the GMT offset.

The following code sets the date/time value using the constructor and displays it in a `Label</api/deprecated/label>`.

``` xojo
Dim d As New Date(1956, 8, 13, 8, 23, 0, -7) 
Label1.Text = d.SQLDateTime
```

## Notes

<div class="note">

<div class="title">

Note

</div>

On Windows (due to the Windows API being used), it is not possible to go back further than 1 January 1601.

</div>

When you create and instantiate a <span class="title-ref">Date</span> object, it is initialized to the current <span class="title-ref">Date</span> and time. Therefore the order of assignment is important: when dealing with a day that exists in one month when the current system <span class="title-ref">Date</span> is in another (such as December 31 when you're in November), setting the Day before the month can result in an unexpected (here 12/01/2011) or even invalid <span class="title-ref">Date</span>. Not setting the year before entering Feb 29 will cause oddities if the current year is not a leap year.

Because <span class="title-ref">Date</span> implements `Operator Compare</api/language/operators/operator_overloads/operator_compare>`, you can use the normal comparison operators to compare <span class="title-ref">Date</span> values.

If you try to set the <span class="title-ref">Date</span> or date/time and the format is incorrect, an `UnsupportedFormatException</api/exceptions/unsupportedformatexception>` is raised.

The <span class="title-ref">Date</span> properties of `FolderItems</api/files/folderitem>` can be accessed via the CreationDate and ModificationDate properties of `FolderItem</api/files/folderitem>` objects. You can get the current <span class="title-ref">Date</span> and time by creating a new <span class="title-ref">Date</span> and reading the values of the Year, Month, Day, Hour, Minute, and Second properties.

In the following code:

``` xojo
Dim v As Variant
Dim d As Date
d = New Date
v = d
```

What is actually happening is that the `Variant</api/data_types/variant>` stores the value of the TotalSeconds property as a `Double</api/data_types/double>`, along with the type information that it is a <span class="title-ref">Date</span> (the Variant's Type property = 7).

Although <span class="title-ref">Date</span> is a class that is subclassed from `Object</api/data_types/additional_types/object>`, `VarType</api/language/vartype>` identifies a <span class="title-ref">Date</span> as a <span class="title-ref">Date</span> data type (Type=7) rather than an `Object</api/data_types/additional_types/object>` (Type=9).

Use the `DateTime<datetime.fromstring>` function to convert a <span class="title-ref">Date</span> string to a <span class="title-ref">Date</span> value.

The TotalSeconds property is the “master” property that stores the date/time associated with a <span class="title-ref">Date</span>. 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 <span class="title-ref">Date</span> properties that return formatted <span class="title-ref">Date</span> or time information are affected by the user's operating system settings. The user's system settings control the formats that are used.

You can use the `Str</api/text/str>` function to obtain the string value of the <span class="title-ref">Date</span> in SQL date/time format, i.e., the following gets the string value of the current date/time:

``` xojo
Dim d As New Date
MsgBox(Str(d))
```

On Windows, the Regional and Language Options panel determines how dates are formatted. On macOS, the <span class="title-ref">Date</span> formats are specified in the Languages & Region System Preferences panel.

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</api/data_types/string>` manipulation functions.

The `DateTime<datetime.fromstring>` function accepts a <span class="title-ref">Date</span> as a string and converts it to a <span class="title-ref">Date</span> object. It accepts only <span class="title-ref">Date</span> strings that are in any of the formats specified by the user's system settings.

## Sample code

This code creates a <span class="title-ref">Date</span> object and sets it to 15 April, 2012.

``` xojo
Dim d As New Date(2012, 4, 15)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This code creates a <span class="title-ref">Date</span> and displays the current <span class="title-ref">Date</span> in a message box.

``` xojo
Dim d As New Date
MsgBox(d.ShortDate)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This code sets a <span class="title-ref">Date</span> object to 10 February 1954.

``` xojo
Dim d As New Date
d.Year = 1954
d.Month = 2
d.Day = 10
MsgBox(d.ShortDate)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following code compares a specific <span class="title-ref">Date</span> to the current \`Date\`:

``` xojo
Dim d As New Date
d.Year = 2012
d.Month = 12
d.Day = 5

Dim today As New Date ' Newly created dates default to the current date and time

If d < today Then
  MsgBox("That's before today!")
End If

If d > today Then
  MsgBox("That's after today!")
End If

If d = today Then
  MsgBox("That's today!")
End If
```

## Compatibility

All project types on all supported operating systems.

## See also

`Object</api/data_types/additional_types/object>` parent class; `System<system.microseconds>`, `DateTime<datetime.fromstring>`, `Str</api/text/str>`, `System<system.ticks>` functions; `FolderItem</api/files/folderitem>`, `DateTime</api/data_types/datetime>` classes
