Timestamp value type (advanced)
Note: storing dates as ISO strings is simpler and more portable.
As the Firestore database comes with a native value type for storing dates called timestamp, we describe using this pattern in this article. The Firestore SDK comes with a Timestamp type that represents a timestamp field.
storing timestamps
As we attempt to store data, the SDK detects Date and Timestamp fields and assumes we want to store them as timestamps.
const user = {
createdAt: new Date(),
createdAt_: Timestamp.now(),
}
When preparing data for the HTTP request, the SDK serializes Date objects and Timestamp objects to plain objects with a single timestampValue property:
{
"createdAt": { "timestampValue": "2025-10-07T18:47:13.279000000Z" },
"createdAt_": { "timestampValue": "2025-10-07T18:47:13.279000000Z" }
},
The database detects this pattern and sets the fields as timestamps.
receiving timestamps
The SDK's Timestamp type represents database timestamps. As we receive timestamp fields from the database, the Firestore SDK instantiates them as Timestamp objects.