Would you help me with comparing a timestamp field with the current date using JavaScript?
This is what I have tried so far:
// Initialize an empty array to store documents
let myDocs = [];
// Call the getDocs function and handle the response
await getDocs(collection(database, 'myCollection')).then((documents) => {
// Loop through each document in the collection
documents.docs.forEach((document) => {
// Compare the timestamp of the document with the current date
if (document.data().createdAt < new Date()) {
// If the timestamp is earlier than the current date, push the data to myDocs array
myDocs.push({ id: document.id, ...document.data() });
}
});
});