Month-day type

Month-day type documentation.

Overview

This type can store a day of the year. It doesn’t store the year or time, just the month and day.

Default format: The default format is MM-dd but you can change it to something else.

Available features

NameSupported
Many multiplicityyes
Default valuesyes
Unique flagno
Required flagyes
Indexable flagyes
Sensitive flagyes
Calculated valueyes
Automatic initializationno
Calculated initial valueno
Aggregationno
Default type rulesno
Default display optionsyes

Display options

Representation

This defines the format for displaying the day. The default format is MM-dd, but you have the option to customize it to your preference.

There are several predefined formats available, which are commonly used. Additionally, you can choose the "Custom" option to define your own format based on the following guidelines:

  • Era designator: G (AD)
  • Year: yy (16), yyyy (2016)
  • Month: MMMM (July), MMM (Jul), MM (07)
  • Day in month: d (9), dd (09)

REST API

Read format

The format for the date is a string using the MM-dd format.

"birthday": "04-16"

Write format

To specify the date, you need to provide a string in the MM-dd format.

"birthday": "04-16"

JavaScript API

Read format

When utilizing the val() method within the wrapper, it will yield a Date object.

// this will print something like "birthday: Wed Jan 11 2017 00:00:00 GMT-0000 (UTC)"
log('birthday: '+record.field('birthday').val());

Since the Date object includes the year and time components, it will be set to the current year and 00:00 using the time zone of the server.

Write format

When writing the value, you have the option to either use a Date object or provide a string in the MM-dd format.

record.field('birthday').val(new Date());
record.field('birthday').val('04-26');

If the provided value is not valid, the field will be silently set to null.

Wrapper method:
addDays(numberOfDays)

This function adds days to the value stored in the field.

Parameters
NameTypeRequiredDescription
numberOfDaysnumberyesThe number of days to add. This value can be either positive or negative.
Returns

sys.data.Wrapper - Returns itself.

Exceptions

badRequest

If numberOfDays is not a number.

Samples
// adds 2 days to the start date
var contact = sys.data.findOne('contacts', {email:'apetersonay@guardian.co.uk'});
log('birthday: '+contact.field('birthday').format());
contact.field('birthday').addDays(2);
log('birthday: '+contact.field('birthday').format());


Wrapper method:
format(pattern)

The format(pattern) method is used to format the day to a string. If a format pattern is provided, it will be used for formatting. If no pattern is provided, the format set in the default display options of the field will be used.

Parameters
NameTypeRequiredDescription
patternstringnoThe pattern to format the date. Please refer to the documentation for display options to understand the available format choices.
If no pattern is supplied, the default display options of the field will be utilized.
Returns

string - The formatted date.

Exceptions

badRequest

If pattern is invalid

Samples
// formats day using 'dd-MM' pattern
var contact = sys.data.findOne('contacts', {email:'apetersonay@guardian.co.uk'});
log('birthday: '+contact.field('birthday').format('dd-MM'));

// formats day using default display options
var contact = sys.data.findOne('contacts', {email:'apetersonay@guardian.co.uk'});
log('birthday: '+contact.field('birthday').format());


Export/Import

Export format

The export format is MM-dd, regardless of the display options configured for that field.

"monthDayField1","monthDayField2"
"02-10","05-24"

Import format

The import format is MM-dd, regardless of the display options configured for that field.

"monthDayField1","monthDayField2"
"02-10","05-24"

Queries

For more information, please refer to the Query Language Documentation.

Available operators

OperatorSupported
equalsyes
notEqualsyes
emptyyes
notEmptyyes
likeno
greateryes
greaterOrEqualsyes
lessyes
lessOrEqualsyes
betweenyes
currentUserFieldno

Query formats

You should pass a string with the format MM-dd. For example:

// finds companies with start date 07-12 
var records_sample = sys.data.find('companies', {'birthday':'07-12'});
log('total: '+records_sample.count());
while (records_sample.hasNext()) {
    log(records_sample.next().label());
}
// finds companies with start date 07-12 
var query_sample = sys.data.createQuery('companies')
    .field('birthday').equals('07-12')
var records_sample = sys.data.find(query_sample);
log('total: '+records_sample.count());
while (records_sample.hasNext()) {
    log(records_sample.next().label());
}
// finds companies with start date 07-12 
GET /data/contacts?birthday=07-12

When utilizing the query builder, you have can use a Date object.

query.field('birthday').equals(new Date());

Aggregate queries

Please refer to the Aggregate Queries Documentation for more detailed information.

Available operators

OperatorSupported
sumno
avgno
firstyes
lastyes
minyes
maxyes

UI queries

Please refer to the UI Queries Documentation for more detailed information.

Matching of values

PropertyDescription
Matching operatorequals
UI queries will attempt to match using the format specified in the default display options of the field.

Available operators

OperatorSupported
Many valuesyes
Greaterno
Greater or equalsno
Lessyes
Less or equalsyes
Betweenyes