# SDateTime

## Index

### Functions Index

| Function Name                                                               |
| --------------------------------------------------------------------------- |
| bool [**Equals** ](#equals)(SDateTime other)                                |
| int [**ComparesTo** ](#comparesto)(SDateTime other)                         |
| string [**FormatLocal** ](#formatlocal)(string format)                      |
| string [**FormatGlobal** ](#formatlocal)(string format)                     |
| string [**Regional** ](#regional)(string region)                            |
| string [**FormatRegional** ](#formatregional)(string region, string format) |
| SDateTime [**AddYears** ](#addyears)(int amount)                            |
| SDateTime [**AddMonths** ](#addmonths)(int amount)                          |
| SDateTime [**AddDays** ](#adddays)(double amount)                           |
| SDateTime [**AddHours** ](#addhours)(double amount)                         |
| SDateTime [**AddMinutes** ](#addminutes)(double amount)                     |
| SDateTime [**AddSeconds** ](#addseconds)(double amount)                     |
| SDateTime [**AddMilliseconds** ](#functionname-1)(double amount)            |
|                                                                             |
|                                                                             |
| **Static Functions**                                                        |
| static SDateTime [**Now**](#now)()                                          |
| static SDateTime [**Server** ](#server)()                                   |
| static SDateTime [**Parse**](#parse) (string input)                         |
| static bool [**IsLeapYear**](#isleapyear) (int year)                        |
| static int [**DaysInMonth** ](#daysinmonth)(int year, int month)            |

### Properties Index

| Property Name                                                |
| ------------------------------------------------------------ |
| int [**Year** ](#year)`get`                                  |
| int [**Month** ](#month)`get`                                |
| int [**Day** ](#day)`get`                                    |
| int [**Hour** ](#hour)`get`                                  |
| int [**Minute** ](#minute)`get`                              |
| int [**Second** ](#second)`get`                              |
| int [**Millisecond** ](#millisecond)`get`                    |
| string [**Local** ](#local)`get`                             |
| string [**Global** ](#global)`get`                           |
| int [**UnixTime** ](#unixtime)`get`                          |
| bool [**IsDaylightSavingTime** ](#isdaylightsavingtime)`get` |

## Functions

### Equals

bool **Equals** (SDateTime other)

*Returns true if the datetimes are same.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

<pre class="language-lua"><code class="lang-lua"><strong>ATargetDateTime = DateTime.Now().AddMinutes(5)
</strong><strong>AreEqual = ATargetDateTime.Equals(DateTime.Now())
</strong></code></pre>

{% endtab %}
{% endtabs %}

### ComparesTo

int **ComparesTo** (SDateTime other)

*Compares two datetimes and returns an integer. 0 == identical. greater than 0 == This datetime is greater than other. less than 0 == This datetime is less than other.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
ATargetDateTime = DateTime.Now().AddMinutes(5)
AreEqual = ATargetDateTime.ComparesTo(DateTime.Now())
```

{% endtab %}
{% endtabs %}

### FormatLocal

string **FormatLocal** (string format)

*Outputs a custom formatted string with the date and time according to local language rules.*

| Parameter | Type   | Description            |
| --------- | ------ | ---------------------- |
| format    | string | See below for examples |

{% tabs %}
{% tab title="Lua" %}

```lua
localTimeCustomFormat = DateTime.Now().FormatLocal("dddd, MMMM dd, yyyy h:mm:ss tt")
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

<pre class="language-lua"><code class="lang-lua"><strong>--Example format strings
</strong><strong>
</strong><strong>--[[ 
</strong><strong>format = "dddd, MMMM dd, yyyy h:mm:ss tt"
</strong>Result: Monday, May 28, 2012 11:35:00 AM

format = "Ldddd, MMMM dd, yyyy"
Result: Monday, May 28, 2012

 format = "h:mm:ss tt"
 Result: 11:35:00 AM

 format = "MMMM dd"
Result: May 28

 format = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT"
Result: Mon, 28 May 2012 11:35:00 GMT

 format = "M/d/yyyy"
 Result: 5/28/2012

 format = "h:mm tt"
Result: 11:35 AM

format = "yyyy'-'MM'-'dd'T'HH':'mm':'ss"
Result: 2012-05-28T11:35:00

format = "yyyy'-'MM'-'dd HH':'mm':'ss'Z'"
 Result: 2012-05-28 11:35:00Z

format = "MMMM, yyyy"
 Result: May, 2012
    --]]
</code></pre>

{% endtab %}
{% endtabs %}

### FunctionName

string **FormatGlobal** (string format)

*Outputs a custom formatted string with the date and time according to global rules (culture invariant).*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
GlobalTimeCustomFormat = DateTime.Now().FormatLocal("dddd, MMMM dd, yyyy h:mm:ss tt")
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--Example format strings

--[[ 
format = "dddd, MMMM dd, yyyy h:mm:ss tt"
Result: Monday, May 28, 2012 11:35:00 AM

format = "Ldddd, MMMM dd, yyyy"
Result: Monday, May 28, 2012

 format = "h:mm:ss tt"
 Result: 11:35:00 AM

 format = "MMMM dd"
Result: May 28

 format = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT"
Result: Mon, 28 May 2012 11:35:00 GMT

 format = "M/d/yyyy"
 Result: 5/28/2012

 format = "h:mm tt"
Result: 11:35 AM

format = "yyyy'-'MM'-'dd'T'HH':'mm':'ss"
Result: 2012-05-28T11:35:00

format = "yyyy'-'MM'-'dd HH':'mm':'ss'Z'"
 Result: 2012-05-28 11:35:00Z

format = "MMMM, yyyy"
 Result: May, 2012
    --]]
```

{% endtab %}
{% endtabs %}

### Regional

string **Regional** (string region)

*Outputs a string with the date and time formatted according to specific regional rules.*

| Parameter | Type   | Description                                                                                                                       |
| --------- | ------ | --------------------------------------------------------------------------------------------------------------------------------- |
| region    | string | [List available here](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c) |

{% tabs %}
{% tab title="Lua" %}

```lua
stringTimeRegional = DateTime.Now().Regional('en-us')
```

{% endtab %}
{% endtabs %}

### FormatRegional

string **FormatRegional** (string region, string format)

*Outputs a custom formatted string with the date and time according to specific regional rules.*

| Parameter | Type   | Description                                                                                                                       |
| --------- | ------ | --------------------------------------------------------------------------------------------------------------------------------- |
| region    | string | [List available here](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c) |
| format    | string | See below                                                                                                                         |

{% tabs %}
{% tab title="Lua" %}

```lua
stringTimeFormatRegional = DateTime.Now().FormatRegional('en-us','dddd, MMMM dd, yyyy h:mm:ss tt')
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--Example format strings

--[[ 
format = "dddd, MMMM dd, yyyy h:mm:ss tt"
Result: Monday, May 28, 2012 11:35:00 AM

format = "Ldddd, MMMM dd, yyyy"
Result: Monday, May 28, 2012

 format = "h:mm:ss tt"
 Result: 11:35:00 AM

 format = "MMMM dd"
Result: May 28

 format = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT"
Result: Mon, 28 May 2012 11:35:00 GMT

 format = "M/d/yyyy"
 Result: 5/28/2012

 format = "h:mm tt"
Result: 11:35 AM

format = "yyyy'-'MM'-'dd'T'HH':'mm':'ss"
Result: 2012-05-28T11:35:00

format = "yyyy'-'MM'-'dd HH':'mm':'ss'Z'"
 Result: 2012-05-28 11:35:00Z

format = "MMMM, yyyy"
 Result: May, 2012
    --]]
```

{% endtab %}
{% endtabs %}

### AddYears

SDateTime **AddYears** (int amount)

*Return a new SDateTime that is the current date time + amount years.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
date5YearsLater = DateTime.Now().AddYears(5)
```

{% endtab %}
{% endtabs %}

### AddMonths

SDateTime **AddMonths** (int amount)

*Return a new SDateTime that is the current date time + amount months.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
date5MonthsLater = DateTime.Now().AddMonths(5)
```

{% endtab %}
{% endtabs %}

### AddDays

SDateTime **AddDays** (double amount)

*Return a new SDateTime that is the current date time + amount days.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
date5DaysLater = DateTime.Now().AddDays(5)
```

{% endtab %}
{% endtabs %}

### AddHours

SDateTime **AddHours** (double amount)

*Return a new SDateTime that is the current date time + amount hours.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
date5HoursLater = DateTime.Now().AddHours(5)
```

{% endtab %}
{% endtabs %}

### AddMinutes

SDateTime **AddMinutes** (double amount)

*Return a new SDateTime that is the current date time + amount minutes.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
date5MinutesLater = DateTime.Now().AddMinutes(5)
```

{% endtab %}
{% endtabs %}

### AddSeconds

SDateTime **AddSeconds** (double amount)

*Return a new SDateTime that is the current date time + amount seconds.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
date5SecondsLater = DateTime.Now().AddSeconds(5)
```

{% endtab %}
{% endtabs %}

### AddMilliseconds

SDateTime **AddMilliseconds** (double amount)

*Return a new SDateTime that is the current date time + amount milliseconds.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
date5MillisecondsLater = DateTime.Now().AddMilliseconds(5)
```

{% endtab %}
{% endtabs %}

### Now

static SDateTime **Now**()

*Creates a new SDateTime object equal to the current local time.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
localDateTime = DateTime.Now()
```

{% endtab %}
{% endtabs %}

### Server

static SDateTime **Server** ()

*Creates a new SDateTime object equal to the current server time.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
serverDateTime = DateTime.Server()
```

{% endtab %}
{% endtabs %}

### Parse

static SDateTime **Parse** (string input)

*Creates a new SDateTime object by attempting to parse a string input. Returns null/nil if the string cannot be parsed.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
parseDateTime = DateTime.Parse('10/3/2022 1:26:02 PM')
```

{% endtab %}
{% endtabs %}

### IsLeapYear

static bool **IsLeapYear** (int year)

*Return true if the specified year is a leap year.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
isLeapYear = DateTime.IsLeapYear(2024)
```

{% endtab %}
{% endtabs %}

### DaysInMonth

static int **DaysInMonth** (int year, int month)

*Return the number of days in the given month for the given year.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
isLeapYear = DateTime.DaysInMonth(2022, 8)
```

{% endtab %}
{% endtabs %}

## Properties

### Year

int **Year** `get`

*Get the independent time unit property of the SDateTime object.*

{% tabs %}
{% tab title="Lua" %}

```lua
currentYear = DateTime.Now().Year
```

{% endtab %}
{% endtabs %}

### Month

int **Month** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
currentMonth = DateTime.Now().Month
```

{% endtab %}
{% endtabs %}

### Day

int **Day** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
currentDay = DateTime.Now().Day
```

{% endtab %}
{% endtabs %}

### Hour

int **Hour** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
currentHour = DateTime.Now().Hour
```

{% endtab %}
{% endtabs %}

### Minute

int **Minute** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
currentMinute = DateTime.Now().Minute
```

{% endtab %}
{% endtabs %}

### Second

int **Second** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
currentSecond = DateTime.Now().Second
```

{% endtab %}
{% endtabs %}

### Millisecond

int **Millisecond** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
currentMillisecond = DateTime.Now().Millisecond
```

{% endtab %}
{% endtabs %}

### Local

string **Local** `get`

*Outputs a string with the date and time formatted according to local language rules.*

{% tabs %}
{% tab title="Lua" %}

```lua
currentTimeStringLocal = DateTime.Now().Local
```

{% endtab %}
{% endtabs %}

### Global

string **Global** `get`

*Outputs a string with the date and time formatted according to global rules (culture invariant).*

{% tabs %}
{% tab title="Lua" %}

```lua
currentTimeStringGlobal = DateTime.Now().Global
```

{% endtab %}
{% endtabs %}

### UnixTime

int **UnixTime** `get`

*Return this time in Unix time, the number of seconds since Jan 1st, 1970.*

{% tabs %}
{% tab title="Lua" %}

```lua
currentUnixTime = DateTime.Now().UnixTime
```

{% endtab %}
{% endtabs %}

### IsDaylightSavingTime

bool **IsDaylightSavingTime** `get`

*Indicates whether this instance of DateTime is within the daylight saving time range for the current time zone.*

{% tabs %}
{% tab title="Lua" %}

```lua
isCurrentTimeDaylightSaving = DateTime.Now().IsDaylightSavingTime
```

{% endtab %}
{% endtabs %}
