DateTime format to SQL format using C#

前端 未结 15 1260
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 02:47

I am trying to save the current date time format from C# and convert it to an SQL Server date format like so yyyy-MM-dd HH:mm:ss so I can use it for my UP

15条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 02:58

    Your problem is in the "Date" property that truncates DateTime to date only. You could put the conversion like this:

    DateTime myDateTime = DateTime.Now;
    string sqlFormattedDate = myDateTime.ToString("yyyy-MM-dd HH:mm:ss"); // <- No Date.ToString()!
    

提交回复
热议问题