在Sql Server中,根据不同style,转换当前日期格式
/*
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)
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联机众书中参考