I create manually a BsonDocument. I have to add a datetime into the document.
How can I convert C# Datetime to MongoDB format ?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You no need to do anything. Just assign date to bson document:
Driver will automatically convert your datetime to mongodb format and store in as UTC date, and will convert back to your local timezone back when you will read it (actually you can change this behavior via driver settings). So, take it in the mind that dates in mongodb always in UTC format.
Documentation about mongodb DateTime: