$dateFromString

Reference type:Cheat sheetFormat:Syntax + example + use case

Reference group: String aggregation expressions

What it does

Parses date text into BSON Date.

Syntax

{$dateFromString: { dateString, format?, timezone?, onError?, onNull? }}

Use case

Normalize imported date strings.

$dateFromString: practical example
{ $set: { parsedAt: { $dateFromString: { dateString: "$dateText", format: "%Y-%m-%d", onError: null, onNull: null } } } }
💡 Explanation Parses date text into BSON Date. When to use it Normalize imported date strings.
Key Takeaways
  • Parses date text into BSON Date.
  • Typical use: Normalize imported date strings.