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

</div>

Class

# Xojo.Core.Date

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

<div class="warning">

<div class="title">

Warning

</div>

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

</div>

## Description

Used to store date/time values. Once a date is created, it cannot be modified, but you can create new dates by applying a DateInterval to an existing date.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                              | Type                               | Read-Only | Shared |
|---------------------------------------------------|------------------------------------|-----------|--------|
| `Day<xojo.core.date.day>`                         | `Integer</api/data_types/integer>` | ✓         |        |
| `DayOfWeek<xojo.core.date.dayofweek>`             | `Integer</api/data_types/integer>` | ✓         |        |
| `DayOfYear<xojo.core.date.dayofyear>`             | `Integer</api/data_types/integer>` | ✓         |        |
| `Hour<xojo.core.date.hour>`                       | `Integer</api/data_types/integer>` | ✓         |        |
| `Minute<xojo.core.date.minute>`                   | `Integer</api/data_types/integer>` | ✓         |        |
| `Month<xojo.core.date.month>`                     | `Integer</api/data_types/integer>` | ✓         |        |
| `Nanosecond<xojo.core.date.nanosecond>`           | `Integer</api/data_types/integer>` | ✓         |        |
| `Second<xojo.core.date.second>`                   | `Integer</api/data_types/integer>` | ✓         |        |
| `SecondsFrom1970<xojo.core.date.secondsfrom1970>` | `Double</api/data_types/double>`   | ✓         |        |
| `TimeZone<xojo.core.date.timezone>`               | `TimeZone</api/os/timezone>`       | ✓         |        |
| `Year<xojo.core.date.year>`                       | `Integer</api/data_types/integer>` | ✓         |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                       | Parameters                                                                                                                                                                                                                                                                                                                                                                               | Returns                              | Shared |
|--------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|--------|
| `Add<xojo.core.date.add>`                  |                                                                                                                                                                                                                                                                                                                                                                                          |                                      |        |
| `Constructor<xojo.core.date.constructor0>` | secondsFrom1970 As `Double</api/data_types/double>`, timezone As `TimeZone</api/os/timezone>`                                                                                                                                                                                                                                                                                            |                                      |        |
| `Constructor<xojo.core.date.constructor1>` | year As `Integer</api/data_types/integer>`, month As `Integer</api/data_types/integer>`, day As `Integer</api/data_types/integer>`, hour As `Integer</api/data_types/integer>` = 0, minute As `Integer</api/data_types/integer>` = 0, seconds As `Integer</api/data_types/integer>` = 0, nanoseconds As `Integer</api/data_types/integer>` = 0, timezone As `TimeZone</api/os/timezone>` |                                      |        |
| `FromText<xojo.core.date.fromtext>`        | input As `String</api/data_types/string>`, loc As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                                                                                                                                                                                                                                                                    | `DateTime</api/data_types/datetime>` |        |
| `Now<xojo.core.date.now>`                  |                                                                                                                                                                                                                                                                                                                                                                                          | `DateTime</api/data_types/datetime>` |        |
| `Subtract<xojo.core.date.subtract>`        |                                                                                                                                                                                                                                                                                                                                                                                          |                                      |        |
| `ToText<xojo.core.date.totext>`            | loc As `Locale</api/os/locale>` = `Nil</api/language/nil>`, dateStyle As `Xojo.Core.Date</api/deprecated/xojo.core.date>` = , timeStyle As `Xojo.Core.Date</api/deprecated/xojo.core.date>` =                                                                                                                                                                                            | `String</api/data_types/string>`     |        |

## Enumerations

<div id="xojo.core.date.formatstyles">

<div class="rst-class">

forsearch

</div>

</div>

Xojo.Core.Date.FormatStyles

### FormatStyles

These are the various styles that can be used to convert a Date to Text with the ToText method.

| Enum   | Description                                      |
|--------|--------------------------------------------------|
| Short  | The short date or time format:                   |
| Medium | The medium date or time format:                  |
| Long   | The long date or time format:                    |
| Full   | The full date or time format:                    |
| None   | Prevents the date or time value from displaying. |

## Property descriptions

<div id="xojo.core.date.day">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.Day

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

The day of the month as a number. The first day is 1. The last day varies by the month.

This property is read-only.

Get the day:

``` xojo
Var d As Date = Xojo.Core.Date.Now
Var day As Integer = d.Day
```

<div id="xojo.core.date.dayofweek">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.DayOfWeek

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

The day of the week, with 1 = Sunday, 2 = Monday, 3 = Tuesday, 4 = Wednesday, 5 = Thursday, 6 = Friday, 7 = Saturday.

This property is read-only.

Ge the day of the week:

``` xojo
Var day As Integer = Xojo.Core.Date.Now.DayOfWeek
```

<div id="xojo.core.date.dayofyear">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.DayOfYear

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

The number of days into the year, 1-based. January 1st is 1.

This property is read-only.

Get the day of the year:

``` xojo
Var yearDay As Integer = Xojo.Core.Date.Now.DayOfYear
```

To check to see if a year is a leap year, you can create a date on the last day of the year (Dec 31) and then check DayOfYear to see if it is greater than 365. For example:

``` xojo
Var year As Integer = 2020
Var d1 As New Xojo.Core.Date(year, 12, 31, Xojo.Core.TimeZone.Current)
If d1.DayOfYear > 365 Then
  ' Leap Year!
Else
  ' Not a leap year
End If
```

<div id="xojo.core.date.hour">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.Hour

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

The hour number for the time portion of the date, using a 24-hour clock. For example, 20 is the value for 8 pm.

This property is read-only.

Get the current hour:

``` xojo
Var d As Xojo.Core.Date = Xojo.Core.Date.Now
Var hour As Integer = d.Hour
```

<div id="xojo.core.date.minute">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.Minute

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

The minute number of the time portion of the date.

This property is read-only.

Get the current minute:

``` xojo
Var d As Date = Xojo.Core.Date.Now
Var minute As Integer = d.Minute
```

<div id="xojo.core.date.month">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.Month

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

The month number of the date. January is month 1, December is month 12.

This property is read-only.

Get the current month:

``` xojo
Var d As Xojo.Core.Date = Xojo.Core.Date.Now
Var month As Integer = d.Month
```

<div id="xojo.core.date.nanosecond">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.Nanosecond

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

The nanoseconds of the time portion of the date. A nanosecond is one billionth of a second.

This property is read-only.

Get the current nanosecond:

``` xojo
Var d As Xojo.Core.Date = Xojo.Core.Date.Now
Var nanosecond As Integer = d.Nanosecond
```

<div id="xojo.core.date.second">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.Second

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

The second number of the time portion of the date.

This property is read-only.

Get the current second:

``` xojo
Var d As Xojo.Core.Date = Xojo.Core.Date.Now
Var second As Integer = d.Second
```

<div id="xojo.core.date.secondsfrom1970">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.SecondsFrom1970

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

The number of seconds since the first instant of 1 January 1970, GMT.

This property is read-only.

This value is also referred to as the Unix epoch, Unix time or Unix timestamp.

You can save this value (in a file or database, for example) and use a Constructor to create a new Date instance for it. Negative values indicate seconds before the first instant of 1 January 1970, GMT.

Get the seconds since 1970 and use it to create a new date:

``` xojo
Var d1 As Date = Xojo.Core.Date.Now
Var seconds As Double = d1.SecondsFrom1970
Var d2 As New Date(seconds, Xojo.Core.TimeZone.Current)
' Both d1 and d2 have the same date value
```

Calculate the number of days between two dates:

``` xojo
Var d1 As New Xojo.Core.Date(2018, 8, 1, Xojo.Core.TimeZone.Current)
Var d2 As New Xojo.Core.Date(2015, 3, 1, Xojo.Core.TimeZone.Current)
' Subtract seconds and convert seconds to days
Var days As Double = (d1.SecondsFrom1970 - d2.SecondsFrom1970) / (24 * 60 * 60) 
```

<div id="xojo.core.date.timezone">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.TimeZone

**TimeZone** As `TimeZone</api/os/timezone>`

The time zone.

This property is read-only.

Get the time zone:

``` xojo
Var d As Date = Xojo.Core.Date.Now
Var tz As Xojo.Core.TimeZone
tz = d.TimeZone
```

To change a date to a new time zone, for example GMT:

``` xojo
' myDate is an existing date
Var GMTZone As New Xojo.Core.TimeZone("GMT")
Var GMTDate As New Xojo.Core.Date(myDate.SecondsFrom1970, GMTZone)
```

<div id="xojo.core.date.year">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.Year

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

The year portion of the date.

This property is read-only.

Get the year:

``` xojo
Var d As Xojo.Core.Date = Xojo.Core.Date.Now
Var year As Integer = d.Year
```

## Method descriptions

<div id="xojo.core.date.add">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.Add

**Add**

You use the "+" operator to add a Date and a Xojo.Core.DateInterval to get a new Date.

Get the date two months from today:

``` xojo
Var twoMonths As New Xojo.Core.DateInterval
twoMonths.Months = 2 ' 2 month interval

' Get date two months from today
Var future As Xojo.Core.Date = Xojo.Core.Date.Now + twoMonths
```

<div id="xojo.core.date.constructor0">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.Constructor

**Constructor**(secondsFrom1970 As `Double</api/data_types/double>`, timezone As `TimeZone</api/os/timezone>`)

<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>

Creates a date using number of seconds from the first instant of 1 January 1970, GMT. Use a negative value to specify a date before this date.

<div id="xojo.core.date.constructor1">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.Constructor

**Constructor**(year As `Integer</api/data_types/integer>`, month As `Integer</api/data_types/integer>`, day As `Integer</api/data_types/integer>`, hour As `Integer</api/data_types/integer>` = 0, minute As `Integer</api/data_types/integer>` = 0, seconds As `Integer</api/data_types/integer>` = 0, nanoseconds As `Integer</api/data_types/integer>` = 0, timezone As `TimeZone</api/os/timezone>`)

<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>

Creates a new date using the supplied values. Use this method to create a specific date.

Create a new date for Aug 1, 2015:

``` xojo
Var d As New Xojo.Core.Date(2015, 8, 1, Xojo.Core.TimeZone.Current) ' Aug 1, 2015
```

Create a new date for Sep 1, 2015 at 3:20pm (and 30 seconds):

``` xojo
Var d As New Xojo.Core.Date(2015, 9, 1, 15, 20, 30, 0, Xojo.Core.TimeZone.Current)
```

Convert a Classic Date to \`Xojo.Core.Date\`:

``` xojo
Var d As New Date(2015, 10, 15)
Var xcd As New Xojo.Core.Date(d.Year, d.Month, d.Day, Xojo.Core.TimeZone.Current)
```

<div id="xojo.core.date.fromtext">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.FromText

**FromText**(input As `String</api/data_types/string>`, loc As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As `DateTime</api/data_types/datetime>`

Converts a textual date to an actual date using the optional locale.

The resulting date is in the current time zone (Xojo.Core.TimeZone.Current).

When no locale is specified, the input text can be in either SQLDate (YYYY-MM-DD) or SQLDateTime (YYYY-MM-DD HH:MM:SS) formats.

If you specify a locale, the *input* text must be formatted to match the locale you specify.

Use format patterns from: [Unicode Date Format Patterns](http://unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns).

If you supply input text that cannot be formatted, then a `RuntimeException</api/exceptions/runtimeexception>` is raised with a Parse Error.

Convert text values to a date:

``` xojo
Var SQLDateTime As Text = "2015-08-01 11:00"
Var myDate1 As Xojo.Core.Date = Xojo.Core.Date.FromText(SQLDateTime)

Var SQLDate As Text = "2018-06-01"
Var myDate2 As Xojo.Core.Date = Xojo.Core.Date.FromText(SQLDate)

Var dateValue As Text = Xojo.Core.Date.Now.ToText(Xojo.Core.Locale.Current) 
Var myDate3 As Xojo.Core.Date = Xojo.Core.Date.FromText(dateValue, Xojo.Core.Locale.Current)
```

<div id="xojo.core.date.now">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.Now

**Now** As `DateTime</api/data_types/datetime>`

The current date and time (local timezone).

Get the current date and time:

``` xojo
Var d As Xojo.Core.Date = Xojo.Core.Date.Now
```

<div id="xojo.core.date.subtract">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.Subtract

**Subtract**

You can subtract a Date from a Date and get a DateInterval.

Get the date two months before today:

``` xojo
Var twoMonths As New Xojo.Core.DateInterval
twoMonths.Months = 2 ' 2 month interval

' Get date two months before today
Var past As Xojo.Core.Date = Xojo.Core.Date.Now - twoMonths
```

Calculate the interval until January 1, 2030:

``` xojo
Var d2 As New Xojo.Core.Date(2030, 1, 1, Xojo.Core.TimeZone.Current)
Var interval As Xojo.Core.DateInterval
interval = d2 - Xojo.Core.Date.Now
```

<div id="xojo.core.date.totext">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.Date.ToText

**ToText**(loc As `Locale</api/os/locale>` = `Nil</api/language/nil>`, dateStyle As `Xojo.Core.Date<xojo.core.date.formatstyles>` = `Xojo.Core.Date.FormatStyles.Medium<xojo.core.date.formatstyles>`, timeStyle As `Xojo.Core.Date<xojo.core.date.formatstyles>` = `Xojo.Core.Date.FormatStyles.Medium<xojo.core.date.formatstyles>`) As `String</api/data_types/string>`

Converts the Date (along with the time component) to a text format using the optional locale and formats.

The default non-locale savvy version (loc is Nil) of ToText returns a date in the SQLDateTime format YYYY-MM-DD HH:MM:SS. When using a loc of Nil, the dateStyle and timeStyle must be FormatStyles.Medium, but since those are the defaults they can be omitted. Because of this there is no need to specifically pass in a loc of Xojo.Locale.Raw.

Example date output with no parameters would be: 2017-10-31 09:38:24

Use a Locale to get a date to use for display purposes. If you provide a Locale, then the specific output formats use what is defined in the locale settings for your OS. Refer to `FormatStyles<xojo.core.date.formatstyles>` for more information.

Also refer to the Localization topic for information on how you can display localized values, particularly with web apps.

Display the current date and time in SQLDateTime format (YYYY-MM-DD HH:MM:SS):

``` xojo
Var d As Xojo.Core.Date = Xojo.Core.Date.Now
Var SQLDateTime As Text = d.ToText ' 2017-10-31 09:38:24
```

To get just the date portion you have to specify a Locale (not Raw). This example uses the current system locale to get just the date part for display:

``` xojo
Using Xojo.Core
Var d As Date = Date.Now
Var t As Text = d.ToText(Locale.Current, Date.FormatStyles.Short, Date.FormatStyles.None)
' t = 10/31/17 (this varies by date and your system locale settings)
```

To display just the time portion you have to specify a Locale and then provide a FormatStyle for the time:

``` xojo
Using Xojo.Core
Var d As Date = Date.Now
Var t As Text = d.ToText(Locale.Current, Date.FormatStyles.None, Date.FormatStyles.Short)
' t = 12:24 PM (this varies by time and your system locale settings)
```

## Notes

Xojo.Core.Date uses [ICU (International Components for Unicode)](http://userguide.icu-project.org/datetime) for its date handling, supporting dates starting from 0001-Jan-01 and switching between Julian and Gregorian calendars on 1582-Oct-04.

You cannot use Var d As New Date to get the current date. Instead, use Var d As Date = Date.Now or more simply, just Date.Now.

To compare dates, use the SecondsFrom1970 property:

``` xojo
If myDate.SecondsFrom1970 > yourDate.SecondsFrom1970 Then
  ' myDate is greater than yourDate
End If
```

## Compatibility

All project types on all supported operating systems.

## See also

`Object</api/data_types/additional_types/object>` parent class; Xojo.Core.DateInterval, Xojo.Core.TimeZone, `DateTime</api/data_types/datetime>` classes
