Convert DateTime in C# to yyyy-MM-dd format and Store it to MySql DateTime Field

前端 未结 5 1227
难免孤独
难免孤独 2021-02-01 12:49

I am trying to convert DateTime format to yyyy-MM-dd format and store it to DateTime object. But it gives me the System DateTime

5条回答
  •  星月不相逢
    2021-02-01 13:21

    Have you tried?

    var isoDateTimeFormat = CultureInfo.InvariantCulture.DateTimeFormat;
    
    // "2013-10-10T22:10:00"
     dateValue.ToString(isoDateTimeFormat.SortableDateTimePattern); 
    
    // "2013-10-10 22:10:00Z"    
    dateValue.ToString(isoDateTimeFormat.UniversalSortableDateTimePattern)
    

    Also try using parameters when you store the c# datetime value in the mySql database, this might help.

提交回复
热议问题