timestamp value type (advanced)
Storing dates as ISO strings is simpler to reason about and is 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 to be transported through an HTTP request, the SDK serializes Date and Timestamp objects to 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 stores those field as timestamps.
receiving timestamps
Timestamp is the designed type to represent database timestamps. As we receive timestamp fields from the database, the Firestore SDK instantiates them as Timestamp objects.