Class DateField

  • Deprecated: The DateField class is deprecated; use the People API advanced service instead.

  • Represents a date field within a Contact, specifically for the Contacts service.

  • Offers limited functionality with getLabel() and setLabel() methods for managing date field labels.

  • Previously provided methods for manipulating date values are now deprecated, including getDay(), getMonth(), getYear(), and setDate().

  • For general date manipulation in Apps Script, use JavaScript's standard Date object.

DateField

Deprecated. Instead, use the People API advanced service

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

Methods

MethodReturn typeBrief description
getLabel() ObjectGets the label for this field.
setLabel(label) (削除) DateField (削除ここまで)Sets the label of this field.

Deprecated methods

MethodReturn typeBrief description
(削除) deleteDateField() (削除ここまで)voidDeletes this date.
(削除) getDay() (削除ここまで)IntegerGets the day of the month for this date.
(削除) getMonth() (削除ここまで)Month Gets the month for this date.
(削除) getYear() (削除ここまで)IntegerGets the year for this date.
(削除) setDate(month, day) (削除ここまで)(削除) DateField (削除ここまで)Sets the date to this day, without a year.
(削除) setDate(month, day, year) (削除ここまで)(削除) DateField (削除ここまで)Sets the date to this day.
(削除) setLabel(label) (削除ここまで)(削除) DateField (削除ここまで)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');

Parameters

NameTypeDescription
labelStringthe new label for this field

Return

(削除) DateField (削除ここまで) — this field, useful for chaining

Authorization

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());

Return

Month — the month

Authorization

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 1
constcontacts=ContactsApp.getContactsByName('John Doe');
constbirthday=contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
birthday.setDate(ContactsApp.Month.APRIL,1);

Parameters

NameTypeDescription
monthMonth the month
dayIntegerthe day

Return

(削除) DateField (削除ここまで) — this date, useful for chaining

Throws

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://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, 1980
constcontacts=ContactsApp.getContactsByName('John Doe');
constbirthday=contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
birthday.setDate(ContactsApp.Month.APRIL,1,1980);

Parameters

NameTypeDescription
monthMonth the month
dayIntegerthe day
yearIntegerthe year

Return

(削除) DateField (削除ここまで) — this date, useful for chaining

Authorization

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 anniversary
constcontacts=ContactsApp.getContactsByName('John Doe');
constfirstDate=contacts[0].getDates()[0];
firstDate.setLabel(ContactsApp.Field.ANNIVERSARY);

Parameters

NameTypeDescription
label(削除) Field (削除ここまで)the new standard label

Return

(削除) DateField (削除ここまで) — this field, useful for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.google.com/m8/feeds

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024年12月02日 UTC.