Skip to content

$toDate

Converts a value to a BSON Date. Strings are parsed using ISO-8601 formats unless options specify otherwise.

Syntax

{ "$toDate": <expression> }

Example

Input

{ "createdAt": "2025-02-01T12:30:00Z" }

Stage

{ "$project": { "createdAt": { "$toDate": "$createdAt" } } }

Output

{ "createdAt": { "$date": "2025-02-01T12:30:00Z" } }