DateTime format to SQL format using C#

前端 未结 15 1196
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  情深已故
    2020-11-28 03:08

    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");
    

提交回复
热议问题