MongoDB Query Language (MQL) Date Expression Operators

Date expression operators extract and manipulate date and time components from date fields. These operators enable you to work with temporal data by extracting specific parts like year, month, day, hour, and performing date arithmetic and formatting operations.

$dateAdd

The $dateAdd operator adds a specified number of time units (day, hour, month etc) to a date.

$dateDiff

The $dateDiff operator calculates the difference between two dates in various units such as years, months, days, etc.

$dateFromParts

The $dateFromParts operator constructs a date from individual components.

$dateFromString

The $dateDiff operator converts a date/time string to a date object.

$dateSubtract

The $dateSubtract operator subtracts a specified amount of time from a date.

$dateToParts

The $dateToParts operator decomposes a date into its individual parts such as year, month, day, and more.

$dateToString

The $dateToString operator converts a date object into a formatted string.

$dateTrunc

The $dateTrunc operator truncates a date to a specified unit.

$dayOfMonth

The $dayOfMonth operator extracts the day of the month from a date.

$dayOfWeek

The $dayOfWeek operator extracts the day of the week from a date.

$dayOfYear

The $dayOfYear operator extracts the day of the year from a date.

$hour

The $hour operator returns the hour portion of a date as a number between 0 and 23.

$isoDayOfWeek

The $isoDayOfWeek operator returns the weekday number in ISO 8601 format, ranging from 1 (Monday) to 7 (Sunday).

$isoWeek

The $isoWeek operator returns the week number of the year in ISO 8601 format, ranging from 1 to 53.

$isoWeekYear

The $isoWeekYear operator returns the year number in ISO 8601 format, which can differ from the calendar year for dates at the beginning or end of the year.

$millisecond

The $millisecond operator extracts the milliseconds portion from a date value.

$minute

The $minute operator extracts the minute portion from a date value.

$month

The $month operator extracts the month portion from a date value.

$second

The $second operator extracts the seconds portion from a date value.

$week

The $week operator returns the week number for a date as a value between 0 and 53.

$year

The $year operator returns the year for a date as a four-digit number.