DateTime format to SQL format using C#

前端 未结 15 1199
伪装坚强ぢ
伪装坚强ぢ 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:07

    If you wanna update a table with that DateTime, you can use your SQL string like this example:

    int fieldId;
    DateTime myDateTime = DateTime.Now
    string sql = string.Format(@"UPDATE TableName SET DateFieldName='{0}' WHERE FieldID={1}", myDateTime.ToString("yyyy-MM-dd HH:mm:ss"), fieldId.ToString());
    

提交回复
热议问题