How to save date properly?

后端 未结 6 1052
耶瑟儿~
耶瑟儿~ 2020-12-08 20:34

I\'m trying to save date (using C# official driver):

val = DateTime.Parse(value).Date; //Here date is {11/11/2011 12:00:00 AM}
var update = Update.Set(\"Date         


        
6条回答
  •  死守一世寂寞
    2020-12-08 21:02

    Mongodb Date value stored in "UTC DateTime" format which comprises of both date & time. so you just cannot store date alone in the field. Instead you can get the date part alone in your application code after retrieving from mongo.

    like in c#

    datevalue.ToString("MM/dd/yyyy");
    

    or

    datevalue.ToShortDateString() 
    

提交回复
热议问题