Date type

Date type documentation.

Overview

This type can store a date without including the time; only the date is stored.

The default format is yyyy-MM-dd, but you have the option to customize it as needed.

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

The format used to display the date is customizable. The default format is yyyy-MM-dd, but you have the flexibility to modify it to your preferences.

You can choose from predefined formats that are commonly used, or you have the option to define a Custom format based on the following rules:

  • Era designator: G (AD)
  • Year: yy (16), yyyy (2016)
  • Month: MMMM (July), MMM (Jul), MM (07)
  • Week in year: w (27)
  • Day in year: D (189)
  • Day in month: d (9), dd (09)
  • Day name in week: EEE (Tue), EEEE (Tuesday)

REST API

Read format

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

"startDate": "2016-07-12"

Write format

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

"startDate": "2016-07-12"

JavaScript API

Read format

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

// this will print something like "date: Sat Jun 15 2013 00:00:00 GMT-0000 (UTC)"
log('date: '+record.field('startDate').val());

Since the Date object includes time, it will be set to 00:00 of the time zone of the server. This approach ensures that the date in the field remains unchanged, while the time is uniformly set to 00:00.

Write format

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

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

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 company = sys.data.findOne('companies', {name:'Oodoo'});
log('start date: '+company.field('startDate').format());
company.field('startDate').addDays(2);
log('start date: '+company.field('startDate').format());


Wrapper method:
format(pattern)

This method formats the date into a string. If a format pattern is provided, it will be utilized. Otherwise, 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 date using 'MM-dd-yyyy' pattern
var company = sys.data.findOne('companies', {name:'Oodoo'});
log('start date: '+company.field('startDate').format('MM-dd-yyyy'));

// formats date using default display options
var company = sys.data.findOne('companies', {name:'Oodoo'});
log('start date: '+company.field('startDate').format());


Export/Import

Export format

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

"dateField1","dateField2"
"2017-02-10","2017-05-24"

Import format

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

"dateField1","dateField2"
"2017-02-10","2017-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-MM-dd. For example:

// finds companies with start date 2016-07-12 
var records_sample = sys.data.find('companies', {'startDate':'2016-07-12'});
log('total: '+records_sample.count());
while (records_sample.hasNext()) {
    log(records_sample.next().label());
}
// finds companies with start date 2016-07-12 
var query_sample = sys.data.createQuery('companies')
    .field('startDate').equals('2016-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 2016-07-12 
GET /data/contacts?startDate=2016-07-12

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

query.field('startDate').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.
Special valuesThere are some special values you can use:
- now: This translates to the current date and time, effectively representing the current moment.
- today: This denotes a range that encompasses the entirety of the present day.
- yesterday: This signifies a range that covers the entirety of the preceding day.
- tomorrow: This indicates a range that includes the entirety of the following day.
- last hour/day/week/month/year:These ranges include all instances from the last hour, day, week, month, or year, respectively.
- this hour/day/week/month/year:These ranges include all instances from the current hour, day, week, month, or year, respectively.
- last X hours/days/weeks/months/years:These ranges encompass all instances from the last X number of hours, days, weeks, months, or years.
- next X hours/days/weeks/months/years: These ranges encompass all instances from the next X number of hours, days, weeks, months, or years.

Available operators

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