Articles → MONGODB → Date And Timestamp Function In MongodbDate And Timestamp Function In MongodbIn this article, we will discuss the Date and Timestamp function in MongoDB.Purpose The Date function returns the current date and the Timestamp function returns the current time.Example In the current example, we will insert the value of the current date and time in the collection.db.DateTimeCollection.insertOne({ Date: new Date(), Time: new Timestamp() })Click to EnlargeThis is how the value of the date and time field is displayed.Click to EnlargeYou can also use the getTimestamp function to get the value of time.Click to EnlargePosted By - Karan Gupta Posted On - Monday, April 3, 2023 Query/Feedback Your Email Id Subject Query/Feedback Characters remaining 250
db.DateTimeCollection.insertOne({ Date: new Date(), Time: new Timestamp() })
Query/Feedback