type="date"
in html saves as a string in firestore.
In the html file.
<input #scheduledStartDate="ngModel" [(ngModel)]="reposition.scheduledStartDate"
name="scheduledStartDate" id="scheduledStartDate" class="input is-normal"
type="date" required placeholder="Leaving...">
from the interface .ts file
scheduledStartDate?: DateTimeFormat;
Also tried
scheduledStartDate?: Date;
With the same result.
Both options save the inputted date value as a string in firestore e.g. "2018-01-02" instead of a timestamp.
Cloud Firestore is optimized for storing large collections of small documents. All documents must be stored in collections. Documents can contain subcollections and nested objects, both of which can include primitive fields like strings or complex objects like lists.
Firestore Update Entire DocumentgetDatabase() → where we want to update a document. doc() → where we'll be passing references of database, collection and ID of a document that we want to update. setDoc() → where we actually pass new data that we want to replace along with the doc() method.
Before saving the javascript object to firestore, just create an instance of Date() and pass the value like this new Date("December 10, 1815")
var docData = {
stringExample: "Hello world!",
booleanExample: true,
numberExample: 3.14159265,
dateExample: new Date("December 10, 1815"),
arrayExample: [5, true, "hello"],
nullExample: null,
objectExample: {
a: 5,
b: {
nested: "foo"
}
}
};
db.collection("data").doc("one").set(docData).then(function() {
console.log("Document successfully written!");
})
Date and time - Chronological - When stored in Cloud Firestore, precise only to microseconds; any additional precision is rounded down.
When a query involves a field with values of mixed types, Cloud Firestore uses a deterministic ordering based on the internal representations.
https://firebase.google.com/docs/firestore/manage-data/data-types https://firebase.google.com/docs/firestore/manage-data/add-data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With