Skip to main content

$toDate

The $toDate operator parses a string representation of a date into a date object.

Input

  • A single string value containing a date in a standard format

Output

  • A date object representing the parsed date

Examples

Parse ISO Date

{
  "$toDate": [
    "2023-01-15T10:30:00Z"
  ]
}
Result: Date object representing January 15, 2023 at 10:30:00 UTC

Parse Different Format

{
  "$toDate": [
    "2023-01-15"
  ]
}
Result: Date object representing January 15, 2023

Field Value

{
  "$toDate": [
    {
      "$input": "date_string"
    }
  ]
}
Result: A date object representing the date in the date_string field