I have table with column COL1(char 23) with full date eg '2007-11-13 12:34:49:012'. Now I want to change my date to '2007-11-12 59:59:59:999' (last moment in day before). Why the convert paremeters dont work property? My query:
convert(varchar(10),convert(date,DateAdd(day,-1,COL1),121)) + ' 23:59:59:999'
After
DateAdd(day,-1,COL1)
i get: "Nov 12 2007" and this is my problem. Finally i get: "Nov 12 200 23:59:59:999"
这个怎么样?
select dateadd(millisecond, -1, dateadd(day, 1, cast(left(col1, 10) as datetime)))
Varchar(10)不够灵通,无法尝试数据varchar(11)
尝试这个:
select cast(dateadd(ms, -1, cast(convert(varchar(8), cast(col1 as datetime), 112) as datetime2)) as varchar(23))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.