Sql Server select datetime without seconds

2020-06-15 03:08发布

I have datetime column value below

2015-01-04 20:37:00.000

I tried below

cast(cast(MyDateColumn as date) as datetime)+cast(datepart(hour,MyDateColumn ) as float)/24
as MyDateColumn 

and

CAST(CONVERT(CHAR(16),MyDateColumn,113) AS datetime) as MyDateColumn

These are did not work for me

How can i get above datetime as 01-04.2015 20:37 ?

7条回答
Summer. ? 凉城
2楼-- · 2020-06-15 03:46
Format(Cast(Convert(varchar(15),Cast(timeval as Time),100) as DateTime),'hh:mm tt') As newtime   

This will remove seconds from time as well as add AM,PM with time.

查看更多
登录 后发表回答