MongoDB Date Operators
MongoDB date operators are a set of special operators used for handling date type fields. They can be used for formatting, converting, and comparing dates in both aggregation and regular queries. This page summarizes the date operators available in MongoDB.
-
$dateFromParts
$dateFromParts
is a date operator in MongoDB that can be used to combine the given date components (such as year, month, day, etc.) into a date object. -
$dateFromString
$dateFromString
is a MongoDB aggregation operator used to convert a string into a date object. -
$dateToParts
The MongoDB$dateToParts
operator can convert dates to corresponding parts such as year, month, day, etc., to enable more flexible data processing and aggregation operations. -
$dateToString
The MongoDB$dateToString
operator is used to convert a date field to a string and format the date into a specified string format. -
$dayOfMonth
The MongoDB$dayOfMonth
operator is an aggregation expression used to extract the day of the month (1-31) from a date field. -
$dayOfWeek
$dayOfWeek
is an aggregation operator in MongoDB used to extract the day of the week information from a date value. -
$dayOfYear
The$dayOfYear
operator is one of the date operators in MongoDB’s aggregation pipeline. -
$hour
The MongoDB$hour
operator is an aggregation operator used to extract the hour portion from a datetime value. -
$isoDayOfWeek
The MongoDB$isoDayOfWeek
operator is an aggregation operator used to extract the day of the week in ISO standard from a date-time value. -
$isoWeek
The MongoDB$isoWeek
operator can be used to process and filter date data. -
$isoWeekYear
In MongoDB,$isoWeekYear
is an aggregation operator used to retrieve the year of an ISO week date. -
$millisecond
In MongoDB, the$millisecond
operator is used to extract the millisecond portion from a date. -
$minute
The$minute
operator is a date operator in MongoDB used to extract the minute portion from a date. -
$month
$month
operator is a date operator in MongoDB aggregation pipeline, which extracts the month from a date field and can be used in aggregation operations. -
$second
$second
is one of the date operators in MongoDB used to handle datetime types. -
$week
In MongoDB, the$week
operator can be used to extract the week number from a date field. -
$year
The$year
operator is one of the operators used to manipulate date-time types and extract the year from a date-time field. -
Date()
In MongoDB, theDate()
method can be used to create a JavaScript Date object that represents a date and time.