Update a Firestore document Timestamp

Stay organized with collections Save and categorize content based on your preferences.

Update a Firestore document Timestamp

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample


_, err := client.Collection("objects").Doc("some-id").Set(ctx, map[string]interface{}{
	"timestamp": firestore.ServerTimestamp,
}, firestore.MergeAll)
if err != nil {
	// Handle any errors in an appropriate way, such as returning them.
	log.Printf("An error has occurred: %s", err)


DocumentReference docRef = db.collection("objects").document("some-id");
// Update the timestamp field with the value from the server
ApiFuture<WriteResult> writeResult = docRef.update("timestamp", FieldValue.serverTimestamp());
System.out.println("Update time : " + writeResult.get());


// Create a document reference
const docRef = db.collection('objects').doc('some-id');

// Update the timestamp field with the value from the server
const res = await docRef.update({
  timestamp: FieldValue.serverTimestamp()


$docRef = $db->collection('samples/php/objects')->document('some-id');
    ['path' => 'timestamp', 'value' => FieldValue::serverTimestamp()]


city_ref = db.collection(u'objects').document(u'some-id')
    u'timestamp': firestore.SERVER_TIMESTAMP


city_ref = firestore.doc "#{collection_path}/new-city-id"
city_ref.update({ timestamp: firestore.field_server_time })

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.