Articles → MONGODB → Isodate Function In Mongodb
Isodate Function In Mongodb
Purpose
What Is ISO 8601 Format?
[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss].[SSS]Z
- YYYY → 4-digit year
- MM → 2-digit month
- DD → 2-digit day
- T → Separator indicating the start of the time component
- hh → 2-digit hour (24-hour format)
- mm → 2-digit minute
- ss → 2-digit second
- SSS → 3-digit millisecond
- Z → Indicates that the time is in UTC
Example
db.mycollection.insertOne({
name: "Time 1",
createdAt: ISODate("2023-06-03")
})
db.mycollection.insertOne({
name: "Time 2",
createdAt: ISODate("2023-06-03 12:23")
})
Output