0

When a date object is created and set into firestore document using below

Firebase function:

var updateData = {status: 'closed', closedOn: new Date()}; 
    db_fs.collection("bookings").doc(bookingDocId).update(updateData).then(async () => {console.log("Document successfully updated!");});

then it goes into firebase like below

enter image description here

But if I set the date in the request (i.e. angular) instead of setting date inside firebase functions

Angular:

var updateData = {status: 'closed', createdOn:  firebase.firestore.Timestamp.fromDate(new Date())}; 

Firebase function:

const data = req.body;
var updateData = data.updateData;  
db_fs.collection("bookings").doc(bookingDocId).update(updateData).then(async () => {console.log("Document successfully updated!");});

then it goes like below

enter image description here

So is there a way in angular/javascript to set the date such that it comes into firebase like shown in the first pic?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
kpvsrkp
  • 335
  • 2
  • 12
  • Make sure the time on your client is the same as the time on the server. – Luuk Jun 05 '21 at 14:05
  • I did not understand. Can you give sample reference – kpvsrkp Jun 05 '21 at 15:57
  • my question is not about the date value. I want the same date structure when date is set from angular – kpvsrkp Jun 05 '21 at 18:06
  • But Google reveals that more people are using firebase and javascript, so this might help you: https://stackoverflow.com/questions/34718668/firebase-timestamp-to-date-and-time – Luuk Jun 05 '21 at 19:00
  • Looking at the code snippet with angular, you're using the Timestamp function from firestore[1] it returns seconds and nanoseconds, so that explains why it's looking that way. Have you tried just putting `new Date()`[2] on the `createdOn` field? [1] https://firebase.google.com/docs/reference/js/firebase.firestore.Timestamp [2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date – Daniel Gomez Jun 07 '21 at 08:27

0 Answers0