# DATE\_FROM\_DATETIME

**The function DATE\_FROM\_DATETIME takes a DateTime and returns the isolated date.**

This function requires one [DateTime](../../variable-data-types/the-number-variable-data-type) as input. It outputs the isolated date described by the given DateTime. As an option, it can also take as input a string indicating the desired timezone of the output. If this timezone differs from the timezone of the DateTime object, DATE\_FROM\_DATETIME will convert the information given by the DateTime to the provided timezone before returning the date.&#x20;

#### Declaration

```javascript
DATE_FROM_DATETIME(datetime, time_zone) -> date
```

&#x20;

#### Parameters

**datetime** (required, type: _DateTime_) Any DateTime.

**time\_zone** (optional, type: _string_) A string representation of the desired timezone. The recognized representations are given by the TZ database names described in [this list of database timezones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).

#### Return Values

**date** (type: _date_) The isolated date described in the given DateTime. If a timezone was provided, this date will be in the designated timezone; otherwise, it will default to the timezone of the given DateTime.

#### Examples

It's possible to hardcode a DateTime, but it quickly gets cumbersome. To avoid this, assume all formulas have access to the following variable:

```javascript
example_date_and_time = {  
 "date": {  
  "day": 1,  
  "month": 4,  
  "year": 2021  
 },  
 "time": {  
  "hour": 16,  
  "minute": 14,  
  "second": 38,  
  "millisecond": 0  
 },  
 "timeZone": "UTC"  
}
```

The following example returns the isolated date given by **example\_date\_and\_time**. Note that the returned values of day, month, and year are exactly the same as the ones provided by the given DateTime:&#x20;

```javascript
DATE_FROM_DATETIME(example_date_and_time) -> {  
 "day": 1,   
 "month": 4,   
 "year": 2021  
}
```

The following example also returns the isolated date from **example\_date\_and\_time**, but this time the output is in the "Asia/Anadyr" timezone. The Asia/Anadyr timezone is twelve hours ahead of UTC, and the time specified by **example\_date\_and\_time** is in the mid-afternoon; during afternoon in UTC, the Asia/Anadyr timezone is experiencing early morning the following day. Thus, the returned date is a day ahead of the date within **example\_date\_and\_time**:

```javascript
DATE_FROM_DATETIME(example_date_and_time, "Asia/Anadyr"} -> {  
 "day": 2,   
 "month": 4,   
 "year": 2021  
}
```

While DATE\_FROM\_DATETIME will run no matter the contents of the string given for **time\_zone**, it only recognizes the TZ database names described in [this list of database timezones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). If the entered string does not describe the desired timezone in a recognizable format, DATE\_FROM\_DATETIME will default to returning the date in the timezone specified by the given DateTime. The following example returns the isolated date from **example\_date\_and\_time**. Note that it it does not recognize "this is a string" as a valid timezone, and so the returned values of day, month, and year are exactly the same as the ones provided by the given DateTime:&#x20;

```javascript
DATE_FROM_DATETIME(example_date_and_time, "this is an string") -> {  
 "day": 1,   
 "month": 4,   
 "year": 2021  
}
```

**example\_date\_and\_time** described a date and time in UTC, but this does not need to be the case in order for DATE\_FROM\_DATETIME to default to the timezone of the given DateTime. To demonstrate, assume the following formulas have access to the following DateTime object, which describes a date and time in the Asia/Anadyr timezone, which is twelve hours ahead of UTC:

```javascript
example_date_and_time2 = {  
 "date": {  
  "day": 1,  
  "month": 4,  
  "year": 2021  
 },  
 "time": {  
  "hour": 10,  
  "minute": 23,  
  "second": 14,  
  "millisecond": 0  
 },  
 "timeZone": "Asia/Anadyr"  
}
```

The following example returns the isolated date from **example\_date\_and\_time2**. Note that the day, month, and year returned are exactly the day, month, and year specified by the given DateTime. That is, the returned date is in the Asia/Anadyr timezone, not UTC:&#x20;

```javascript
DATE_FROM_DATETIME(example_date_and_time2) -> {  
 "day": 1,   
 "month": 4,   
 "year": 2021  
}
```

This last example returns the isolated date given by **example\_date\_and\_time2** in UTC. Because the time given by **example\_date\_and\_time2** is in the morning in the Asia/Anadyr timezone, and the Asia/Anadyr timezone is twelve hours ahead of UTC, note that the returned date is a day behind the date specified in **example\_date\_and\_time2**:

```javascript
DATE_FROM_DATETIME(example_date_and_time2, "UTC") -> {  
 "day": 31,   
 "month": 3,   
 "year": 2021  
}
```
