您的位置:首页 > 数据库

在Sql Server中,根据不同style,转换当前日期格式

2007-06-07 17:35 246 查看
/*
select getdate() = 2007-06-07 17:07:30.623

CONVERT (data_type[(length)], expression [, style])

style:日期格式根据style显示

select convert(char(10),getDate(),120) = 2007-06-07
*/

--取年份和月份 2007-06-07 由0开始取至8位,得 2007-06
select Substring((convert(char(10),getdate(),120)),0,8)

--取当前时间 17:14:29
select convert(varchar(10),getdate(),108)

关于style的样式,可以在Sql Server联机众书中参考
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: