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.
// 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.constcontacts=ContactsApp.getContactsByName('John Doe');constaddressFields=contacts[0].getAddresses();for(leti=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://www.google.com/m8/feeds
setLabel(label)
Sets the label of this field.
// 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.constcontacts=ContactsApp.getContactsByName('John Doe');constaddressFields=contacts[0].getAddresses();addressFields[0].setLabel('Apartment');
Scripts that use this method require authorization with one or more of the following 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.
// Deletes all the dates that are set for contact 'John Doe'constcontacts=ContactsApp.getContactsByName('John Doe');constdates=contacts[0].getDates();for(leti=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://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() method returns the day of the week instead.
// Logs the day of the birthday for contact 'John Doe'constcontacts=ContactsApp.getContactsByName('John Doe');constbirthday=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://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.
// Logs the month of the birthday for contact 'John Doe'constcontacts=ContactsApp.getContactsByName('John Doe');constbirthday=contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];Logger.log(birthday.getMonth());
Scripts that use this method require authorization with one or more of the following 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.
// Logs the year of the birthday for contact 'John Doe'constcontacts=ContactsApp.getContactsByName('John Doe');constbirthday=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://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.
// Sets the birthday for contact 'John Doe' to April 1constcontacts=ContactsApp.getContactsByName('John Doe');constbirthday=contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];birthday.setDate(ContactsApp.Month.APRIL,1);
Scripts that use this method require authorization with one or more of the following 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.
// Sets the birthday for contact 'John Doe' to April 1, 1980constcontacts=ContactsApp.getContactsByName('John Doe');constbirthday=contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];birthday.setDate(ContactsApp.Month.APRIL,1,1980);
Scripts that use this method require authorization with one or more of the following 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'.
// Retrieves the first date that's set for contact 'John Doe' and re-labels// it as an anniversaryconstcontacts=ContactsApp.getContactsByName('John Doe');constfirstDate=contacts[0].getDates()[0];firstDate.setLabel(ContactsApp.Field.ANNIVERSARY);
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-02 UTC."],[[["\u003cp\u003e\u003cstrong\u003eDeprecated:\u003c/strong\u003e The \u003ccode\u003eDateField\u003c/code\u003e class is deprecated; use the People API advanced service instead.\u003c/p\u003e\n"],["\u003cp\u003eRepresents a date field within a Contact, specifically for the Contacts service.\u003c/p\u003e\n"],["\u003cp\u003eOffers limited functionality with \u003ccode\u003egetLabel()\u003c/code\u003e and \u003ccode\u003esetLabel()\u003c/code\u003e methods for managing date field labels.\u003c/p\u003e\n"],["\u003cp\u003ePreviously provided methods for manipulating date values are now deprecated, including \u003ccode\u003egetDay()\u003c/code\u003e, \u003ccode\u003egetMonth()\u003c/code\u003e, \u003ccode\u003egetYear()\u003c/code\u003e, and \u003ccode\u003esetDate()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eFor general date manipulation in Apps Script, use JavaScript's standard \u003ccode\u003eDate\u003c/code\u003e object.\u003c/p\u003e\n"]]],[],null,["DateField\n\n\n**Deprecated.** Instead, use the [People API advanced\nservice](/apps-script/advanced/people)\n\nA date field in a Contact.\n\nThis class is only used by the Contacts service, and dates used elsewhere in App Script use\nJavaScript's standard [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) object. \n\nMethods\n\n| Method | Return type | Brief description |\n|--------------------------------------|----------------|--------------------------------|\n| [getLabel()](#getLabel()) | `Object` | Gets the label for this field. |\n| [setLabel(label)](#setLabel(String)) | [DateField](#) | Sets the label of this field. |\n\nDeprecated methods\n\n| Method | Return type | Brief description |\n|--------------------------------------------------------------|-----------------------------|--------------------------------------------------------------------|\n| [deleteDateField()](#deleteDateField()) | `void` | Deletes this date. |\n| [getDay()](#getDay()) | `Integer` | Gets the day of the month for this date. |\n| [getMonth()](#getMonth()) | [Month](../base/month.html) | Gets the month for this date. |\n| [getYear()](#getYear()) | `Integer` | Gets the year for this date. |\n| [setDate(month, day)](#setDate(Month,Integer)) | [DateField](#) | Sets the date to this day, without a year. |\n| [setDate(month, day, year)](#setDate(Month,Integer,Integer)) | [DateField](#) | Sets the date to this day. |\n| [setLabel(label)](#setLabel(Field)) | [DateField](#) | Sets the label of this field, such as 'Birthday' or 'Anniversary'. |\n\nDetailed documentation \n\n`get``Label()` \nGets the label for this field. This may be a Field, ExtendedField, or a String.\n\n```javascript\n// Logs the label for all the address fields associated with contact\n// 'John Doe'. This method can be similarly called for any field that has\n// a label.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst addressFields = contacts[0].getAddresses();\nfor (let i = 0; i \u003c addressFields.length; i++) {\n Logger.log(addressFields[i].getLabel());\n}\n```\n\nReturn\n\n\n`Object` --- the label for this field\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n`set``Label(label)` \nSets the label of this field.\n\n```javascript\n// Sets the label to 'Apartment' for the first address field associated\n// with contact 'John Doe'. This method can be similarly called for any\n// field that has a label.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst addressFields = contacts[0].getAddresses();\naddressFields[0].setLabel('Apartment');\n```\n\nParameters\n\n| Name | Type | Description |\n|---------|----------|------------------------------|\n| `label` | `String` | the new label for this field |\n\nReturn\n\n\n[DateField](#) --- this field, useful for chaining\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\nDeprecated methods \n\n`delete``Date``Field()` \n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nDeletes this date.\n\n```javascript\n// Deletes all the dates that are set for contact 'John Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst dates = contacts[0].getDates();\nfor (let i = 0; i \u003c dates.length; i++) {\n dates[i].deleteDateField();\n}\n```\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n`get``Day()` \n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nGets the day of the month for this date.\n\nNote: For standard JavaScript Date objects the [`get``Day()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay) method returns the day of the week instead.\n\n```javascript\n// Logs the day of the birthday for contact 'John Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];\nLogger.log(birthday.getDay());\n```\n\nReturn\n\n\n`Integer` --- the day of the month\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n`get``Month()` \n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nGets the month for this date.\n\n```javascript\n// Logs the month of the birthday for contact 'John Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];\nLogger.log(birthday.getMonth());\n```\n\nReturn\n\n\n[Month](../base/month.html) --- the month\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n`get``Year()` \n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nGets the year for this date.\n\n```javascript\n// Logs the year of the birthday for contact 'John Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];\nLogger.log(birthday.getYear());\n```\n\nReturn\n\n\n`Integer` --- the year\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n`set``Date(month, day)` \n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nSets the date to this day, without a year.\n\nThis method only applies to date fields that don't require a year, such as birthdays.\n\n```javascript\n// Sets the birthday for contact 'John Doe' to April 1\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];\nbirthday.setDate(ContactsApp.Month.APRIL, 1);\n```\n\nParameters\n\n| Name | Type | Description |\n|---------|-----------------------------|-------------|\n| `month` | [Month](../base/month.html) | the month |\n| `day` | `Integer` | the day |\n\nReturn\n\n\n[DateField](#) --- this date, useful for chaining\n\nThrows\n\n\n[`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) --- if this date field requires a year\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n`set``Date(month, day, year)` \n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nSets the date to this day.\n\n```javascript\n// Sets the birthday for contact 'John Doe' to April 1, 1980\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];\nbirthday.setDate(ContactsApp.Month.APRIL, 1, 1980);\n```\n\nParameters\n\n| Name | Type | Description |\n|---------|-----------------------------|-------------|\n| `month` | [Month](../base/month.html) | the month |\n| `day` | `Integer` | the day |\n| `year` | `Integer` | the year |\n\nReturn\n\n\n[DateField](#) --- this date, useful for chaining\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n`set``Label(label)` \n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nSets the label of this field, such as 'Birthday' or 'Anniversary'.\n\n```javascript\n// Retrieves the first date that's set for contact 'John Doe' and re-labels\n// it as an anniversary\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst firstDate = contacts[0].getDates()[0];\nfirstDate.setLabel(ContactsApp.Field.ANNIVERSARY);\n```\n\nParameters\n\n| Name | Type | Description |\n|---------|------------------------------------------------|------------------------|\n| `label` | [Field](/apps-script/reference/contacts/field) | the new standard label |\n\nReturn\n\n\n[DateField](#) --- this field, useful for chaining\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`"]]