Year-Month type

Year-Month type documentation.

Overview

This field type is capable of storing a specific year and month. It does not include the day or time information, focusing solely on the year and month.

Default format: The default format is yyyy-MM, although it can be customized to a different format.

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 month and year. The default format is yyyy-MM, 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)

REST API

Read format

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

"nextHolidays": "2016-07"

Write format

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

"nextHolidays": "2016-07"

JavaScript API

Read format

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

// this will print something like "holidays: Thu Jun 01 2017 00:00:00 GMT-0000 (UTC)"
log('holidays: '+record.field('nextHolidays').val());

As the Date object contains day and time information, it will be set to 00:00 of the first day of the month 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 yyyy-MM format.

record.field('nextHolidays').val(new Date());
record.field('nextHolidays').val('2016-07');

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

Wrapper method:
format(pattern)

Formats the month into a string. If a format pattern is provided, it will be used; otherwise, the format set in the default display options of the field will be used.

Parameters
NameTypeRequiredDescription
patternstringnoThe pattern parameter specifies the format for formatting the month. Please refer to the documentation for display options to understand the available format options.
If no pattern is provided, the default display options of the field will be used.
Returns

string - The formatted month.

Exceptions

badRequest

If pattern is invalid

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

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


Export/Import

Export format

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

"yearMonthField1","yearMonthField2"
"02-10","05-24"

Import Format

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

"yearMonthField1","yearMonthField2"
"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 yyyy-DD. For example:

// finds contacts with holidays in 2017-07 
var records_sample = sys.data.find('contacts', {'nextHolidays': '2017-07'});
log('total: '+records_sample.count());
while (records_sample.hasNext()) {
    log(records_sample.next().label());
}
// finds contacts with holidays in 2017-07 
var query_sample = sys.data.createQuery('contacts')
    .field('nextHolidays').equals('2017-07')
var records_sample = sys.data.find(query_sample);
log('total: '+records_sample.count());
while (records_sample.hasNext()) {
    log(records_sample.next().label());
}
// finds contacts with holidays in 2017-07 
GET /data/contacts?nextHolidays=2017-07

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

query.field('nextHolidays').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