Skip to content
Advertisement

Saving Date to firestore document in Javascript

I have a function that converts date string to Date

JavaScript

Then I use as following:

JavaScript

But on firebase console, the birthdate is stored as an empty array as the image bellow:

What I am doing wrong?

Advertisement

Answer

convertStringToDate returns a Date object, which if you console log, will show up something like this:

JavaScript

If you want to store it as a string, you need to convert that Date object to a string with something like birthdate.toIsoString(). But because this is Firebase, if you want to store an actual date, you want to convert it to a Firestore timestamp:

JavaScript

When you retrieve it later, you’d use:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement