| 
    << Click to Display Table of Contents >> DateTime | 
    
    
     ![]() ![]()  
     | 
  
DataTime Functions List:
Functions  | 
Syntax  | 
Instructions  | 
Examples  | 
|---|---|---|---|
dateFromParts  | 
{$dateFromParts : { 'year': <year>, 'month': <month>, 'day': <day>, 'hour': <hour>, 'minute': <minute>, 'second':<second>, 'millisecond': <ms>, 'timezone': <tzExpression>} }  | 
Constructs and returns a Date object given the date’s constituent properties.  | 
For example: { $ dateFromParts : { 'year' : 2017 , 'month' : 14 , 'day' : 1 , 'hour' : 12 } }  | 
dateFromString  | 
{ $dateFromString: {dateString: <dateStringExpression>, format: <formatStringExpression>, timezone: <tzExpression>, onError: <onErrorExpression>, onNull:<onNullExpression>} }  | 
Converts a date/time string to a date object.  | 
For example: { $dateFromString: { dateString: "15-06-2018", format: "%d-%m-%Y"} }  | 
dateToParts  | 
{$dateToParts: {'date' : <dateExpression>, 'timezone':<timezone>, 'iso8601' : <boolean>} }  | 
Returns a document that contains the constituent parts of a given BSON Date value as individual properties. The properties returned are year, month, day, hour, minute, second and millisecond.  | 
For example: { $dateToParts: { date: "$date", timezone: "America/New_York" } }  | 
dateToString  | 
{ $dateToString: { date:<dateExpression>, format:<formatString>, timezone:<tzExpression>, onNull:<expression> } }  | 
Converts a date object to a string according to a user-specified format.  | 
For example: 
 { $dateToString: { format: "%Y-%m-%d", date: ISODate("2014-01-01T08:15:39.736Z") } }  | 
dayOfMonth  | 
{ $dayOfMonth: <dateExpression> }  | 
Returns the day of the month for a date as a number between 1 and 31.  | 
For example: 
 { $dayOfMonth: new Date("2016-01-01") }  | 
dayOfWeek  | 
{ $dayOfWeek: <dateExpression> }  | 
Returns the day of the week for a date as a number between 1 (Sunday) and 7 (Saturday).  | 
For example: { $dayOfWeek: new Date("2016-01-01") }  | 
dayOfYear  | 
{ $dayOfYear: <dateExpression> }  | 
Returns the day of the year for a date as a number between 1 and 366.  | 
For example: { $dayOfYear: new Date("2016-01-01") }  | 
hour  | 
{ $hour: <dateExpression> }  | 
Returns the hour portion of a date as a number between 0 and 23.  | 
For example: { $hour: new Date("2016-01-01T12:00:00Z") }  | 
isoDayOfWeek  | 
{ $isoDayOfWeek: <dateExpression> }  | 
Returns the weekday number in ISO 8601 format, ranging from 1 (for Monday) to 7 (for Sunday).  | 
For example: { $isoDayOfWeek: new Date("2016-01-01") }  | 
isoWeek  | 
{ $isoWeek: <dateExpression> }  | 
Returns the week number in ISO 8601 format, ranging from 1 to 53. Week numbers start at 1 with the week (Monday through Sunday) that contains the year’s first Thursday.  | 
For example: { $isoWeek: { date: new Date("Jan 4, 2016") } }  | 
isoWeekYear  | 
{ $isoWeekYear: <dateExpression> }  | 
Returns the year number in ISO 8601 format. The year starts with the Monday of week 1 and ends with the Sunday of the last week.  | 
For example: { $isoWeek: { $isoWeekYear: new Date("2015-05-26") }  | 
millisecond  | 
{ $millisecond: <dateExpression> }  | 
Returns the millisecond portion of a date as an integer between 0 and 999.  | 
For example: { $millisecond: ISODate("2014-01-01T08:15:39.736Z") }  | 
minute  | 
{ $minute: <dateExpression> }  | 
Returns the minute portion of a date as a number between 0 and 59.  | 
For example: { $minute: new Date("2016-01-01T12:01:00Z") }  | 
month  | 
{ $month: <dateExpression> }  | 
Returns the month of a date as a number between 1 and 12.  | 
For example: { $month: { date: new Date("Nov 7, 2003") } }  | 
second  | 
{ $second: <dateExpression> }  | 
Returns the second portion of a date as a number between 0 and 59, but can be 60 to account for leap seconds.  | 
For example: { $second: new Date("2012-11-06T00:14:20") }  | 
week  | 
{ $week: <dateExpression> }  | 
Returns the week of the year for a date as a number between 0 and 53.  | 
For example: { $week: { date: new Date("2016-01-04") } }  | 
year  | 
{ $year: <dateExpression> }  | 
Returns the year portion of a date.  | 
For example: { $year: new Date("2016-01-01") }  |