How to update Firestore Timestamp to a future value

Viewed 63

We have a check-in and check-out component in our web app that simply uses firebase timestamps. However, we need the ability to edit those timestamps in the event someone makes a mistake.

checkInTimeStamp: fb.firestore.FieldValue.serverTimestamp("17:00") simply returns the current time.

Instead of 17:00, what object do we need to pass through the function to get the correct timestamp?

1 Answers

The serverTimestamp() generates current timestamp on server side. You can use a Date object instead to store a future date:

const futureDate = new Date();

// update date to future time
futureDate.setDate(futureDate.getDate() + 5);

db.document('col/doc').set({ checkInTimeStamp: futureDate })

Checkout other method like setDate() in MDN docs.

Related