Google Apps Script

Class DateField

A date field in a Contact.

Methods

MethodReturn typeBrief description
deleteDateField()voidDeletes this date.
getDay()IntegerGets the day of the month for this date.
getLabel()ObjectGets the label for this field.
getMonth()MonthGets the month for this date.
getYear()IntegerGets the year for this date.
setDate(month, day)DateFieldSets the date to this day, without a year.
setDate(month, day, year)DateFieldSets the date to this day.
setLabel(label)DateFieldSets the label of this field, such as 'Birthday' or 'Anniversary'.
setLabel(label)DateFieldSets the label of this field.

Detailed documentation

deleteDateField()

Deletes this date.

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

getDay()

Gets the day of the month for this date.

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

Return

Integer — the day of the month


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.
 var contacts = ContactsApp.getContactsByName('John Doe');
 var addressFields = contacts[0].getAddresses();
 for (var i = 0; i < addressFields.length; i++) {
   Logger.log(addressFields[i].getLabel());
 }
 

Return

Object — the label for this field


getMonth()

Gets the month for this date.

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

Return

Month — the month


getYear()

Gets the year for this date.

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

Return

Integer — the year


setDate(month, day)

Sets the date to this day, without a year. This method only applies to birthdays. Other dates require a year to be specified.

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

Parameters

NameTypeDescription
monthMonththe month
dayIntegerthe day

Return

DateField — this date, useful for chaining


setDate(month, day, year)

Sets the date to this day.

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

Parameters

NameTypeDescription
monthMonththe month
dayIntegerthe day
yearIntegerthe year

Return

DateField — this date, useful for chaining


setLabel(label)

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

Parameters

NameTypeDescription
labelFieldthe new standard label

Return

DateField — this field, useful for chaining


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.
 var contacts = ContactsApp.getContactsByName('John Doe');
 var addressFields = contacts[0].getAddresses();
 addressFields[0].setLabel('Apartment');
 

Parameters

NameTypeDescription
labelStringthe new label for this field

Return

DateField — this field, useful for chaining

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.