DateField


**Deprecated.** Instead, use the [People API advanced
service](https://developers.google.com/apps-script/advanced/people)

A date field in a Contact.

This class is only used by the Contacts service, and dates used elsewhere in App Script use
JavaScript's standard [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) object.

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/contacts/date-field#getLabel()` | `Object` | Gets the label for this field. |
| `https://developers.google.com/apps-script/reference/contacts/date-field#setLabel(String)` | `https://developers.google.com/apps-script/reference/contacts/date-field#` | Sets the label of this field. |

### Deprecated methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/contacts/date-field#deleteDateField()` | `void` | Deletes this date. |
| `https://developers.google.com/apps-script/reference/contacts/date-field#getDay()` | `Integer` | Gets the day of the month for this date. |
| `https://developers.google.com/apps-script/reference/contacts/date-field#getMonth()` | `https://developers.google.com/apps-script/reference/base/month.html` | Gets the month for this date. |
| `https://developers.google.com/apps-script/reference/contacts/date-field#getYear()` | `Integer` | Gets the year for this date. |
| `https://developers.google.com/apps-script/reference/contacts/date-field#setDate(Month,Integer)` | `https://developers.google.com/apps-script/reference/contacts/date-field#` | Sets the date to this day, without a year. |
| `https://developers.google.com/apps-script/reference/contacts/date-field#setDate(Month,Integer,Integer)` | `https://developers.google.com/apps-script/reference/contacts/date-field#` | Sets the date to this day. |
| `https://developers.google.com/apps-script/reference/contacts/date-field#setLabel(Field)` | `https://developers.google.com/apps-script/reference/contacts/date-field#` | Sets the label of this field, such as 'Birthday' or 'Anniversary'. |

## Detailed documentation

### `getLabel()`

Gets the label for this field. This may be a Field, ExtendedField, or a String.

```javascript
// Logs the label for all the address fields associated with contact
// 'John Doe'. This method can be similarly called for any field that has
// a label.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
for (let i = 0; i < addressFields.length; i++) {
  Logger.log(addressFields[i].getLabel());
}
```

#### Return


`Object` --- the label for this field

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.google.com/m8/feeds`

*** ** * ** ***

### `setLabel(label)`

Sets the label of this field.

```javascript
// Sets the label to 'Apartment' for the first address field associated
// with contact 'John Doe'. This method can be similarly called for any
// field that has a label.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
addressFields[0].setLabel('Apartment');
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `label` | `String` | the new label for this field |

#### Return


`https://developers.google.com/apps-script/reference/contacts/date-field#` --- this field, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.google.com/m8/feeds`

## Deprecated methods

### `deleteDateField()`


**Deprecated.** This function is deprecated and should not be used in new scripts.

Deletes this date.

```javascript
// Deletes all the dates that are set for contact 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const dates = contacts[0].getDates();
for (let i = 0; i < dates.length; i++) {
  dates[i].deleteDateField();
}
```

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.google.com/m8/feeds`

*** ** * ** ***

### `getDay()`


**Deprecated.** This function is deprecated and should not be used in new scripts.

Gets the day of the month for this date.

Note: For standard JavaScript Date objects the [`getDay()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay) method returns the day of the week instead.

```javascript
// Logs the day of the birthday for contact 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
Logger.log(birthday.getDay());
```

#### Return


`Integer` --- the day of the month

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.google.com/m8/feeds`

*** ** * ** ***

### `getMonth()`


**Deprecated.** This function is deprecated and should not be used in new scripts.

Gets the month for this date.

```javascript
// Logs the month of the birthday for contact 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
Logger.log(birthday.getMonth());
```

#### Return


`https://developers.google.com/apps-script/reference/base/month.html` --- the month

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.google.com/m8/feeds`

*** ** * ** ***

### `getYear()`


**Deprecated.** This function is deprecated and should not be used in new scripts.

Gets the year for this date.

```javascript
// Logs the year of the birthday for contact 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
Logger.log(birthday.getYear());
```

#### Return


`Integer` --- the year

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.google.com/m8/feeds`

*** ** * ** ***

### `setDate(month, day)`


**Deprecated.** This function is deprecated and should not be used in new scripts.

Sets the date to this day, without a year.

This method only applies to date fields that don't require a year, such as birthdays.

```javascript
// Sets the birthday for contact 'John Doe' to April 1
const contacts = ContactsApp.getContactsByName('John Doe');
const birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
birthday.setDate(ContactsApp.Month.APRIL, 1);
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `month` | `https://developers.google.com/apps-script/reference/base/month.html` | the month |
| `day` | `Integer` | the day |

#### Return


`https://developers.google.com/apps-script/reference/contacts/date-field#` --- this date, useful for chaining

#### Throws


[`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) --- if this date field requires a year

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.google.com/m8/feeds`

*** ** * ** ***

### `setDate(month, day, year)`


**Deprecated.** This function is deprecated and should not be used in new scripts.

Sets the date to this day.

```javascript
// Sets the birthday for contact 'John Doe' to April 1, 1980
const contacts = ContactsApp.getContactsByName('John Doe');
const birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
birthday.setDate(ContactsApp.Month.APRIL, 1, 1980);
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `month` | `https://developers.google.com/apps-script/reference/base/month.html` | the month |
| `day` | `Integer` | the day |
| `year` | `Integer` | the year |

#### Return


`https://developers.google.com/apps-script/reference/contacts/date-field#` --- this date, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.google.com/m8/feeds`

*** ** * ** ***

### `setLabel(label)`


**Deprecated.** This function is deprecated and should not be used in new scripts.

Sets the label of this field, such as 'Birthday' or 'Anniversary'.

```javascript
// Retrieves the first date that's set for contact 'John Doe' and re-labels
// it as an anniversary
const contacts = ContactsApp.getContactsByName('John Doe');
const firstDate = contacts[0].getDates()[0];
firstDate.setLabel(ContactsApp.Field.ANNIVERSARY);
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `label` | `https://developers.google.com/apps-script/reference/contacts/field` | the new standard label |

#### Return


`https://developers.google.com/apps-script/reference/contacts/date-field#` --- this field, useful for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.google.com/m8/feeds`