sql server时间函数
https://www.cnblogs.com/JimmyZheng/archive/2010/07/16/1778786.html
时间转换:
select convert(varchar(12),getdate(),101) 07/16/2010
select convert(varchar(12),getdate(),102) 2010.07.16
select convert(varchar(12),getdate(),103) 16/07/2010
select convert(varchar(12),getdate(),104) 16.07.2010
select convert(varchar(12),getdate(),105) 16-07-2010
select convert(varchar(12),getdate(),106) 16 Jul 2010
select convert(varchar(12),getdate(),107) Jul 16, 2010
select convert(varchar(12),getdate(),108) 11:58:49
select convert(varchar(12),getdate(),109) Jul 16 2010
select convert(varchar(12),getdate(),110) 07-16-2010
select convert(varchar(12),getdate(),111) 2010/07/16
select convert(varchar(12),getdate(),112) 20100716
select convert(varchar(12),getdate(),113) 16 Jul 2010
select convert(varchar(12),getdate(),114) 11:59:35:930
当月第一天
select dateadd(mm,datediff(mm,0,getdate()),0)
本周星期一
select dateadd(wk,datediff(wk,0,getdate()),0)
本年第一天
select dateadd(yyyy,datediff(yyyy,0,getdate()),0)
--本月最后1天
select dateadd(ms,-3,dateadd(mm,datediff(mm,0,getdate())+1,0))
--本周最后一天,注意sql精确到3毫秒。。。
select dateadd(ms,-3,dateadd(wk,datediff(wk,0,getDate())+1,0));
--本月的第一个星期一
select dateadd(wk,dateDiff(wk,0,dateadd(dd,6-datepart(day,getdate()),getdate())),0);