How to convert datetime to date only (with time set to 00:00:00.000)

前端 未结 11 1989
Happy的楠姐
Happy的楠姐 2021-02-13 12:42

I have a string \'2009-06-24 09:52:43.000\', which I need to insert to a DateTime column of a table.

But I don\'t care about the time, just want to insert it as 2009-06-

11条回答
  •  梦谈多话
    2021-02-13 13:20

    A variety of hacks:

    • Convert your string to a datetime, then back again using the optional "style" parameter to convert to convert your datetime to a string using just the date portion
    • use substring to chop off the end
    • round the datetime using floor

提交回复
热议问题