Reputation: 15
I'm trying to take a Date() object and turn it into a proper Firebase timestamp for data. I found this function in the docs but it doesn't work for me. When I try to save as Date(date) it will save as a string instead of timestamp. any help?
firebase
.firestore()
.collection("articles")
.add({
url: url,
archive: archive.docId,
article: articleState,
published: firebase.firestore.Timestamp.fromDate(date);})
Upvotes: 1
Views: 766
Reputation: 317342
You don't need to do anything to a Date object in order for it to become a timestamp. The SDK will do that automatically.
firebase
.firestore()
.collection("articles")
.add({
url: url,
archive: archive.docId,
article: articleState,
published: date
})
It has to be an actual Date object for this to work. For example:
let date = new Date()
If you're having problems creating a Date object (we can't see what you're doing), that sounds like a different problem entirely.
Upvotes: 0