MYSQL :
TIMESTAMP:
将Long类型时间转化成日期时间 FROM_UNIXTIME(qyrq)
将日期时间转化成Long类型时间 UNIX_TIMESTAMP(NOW()) ,UNIX_TIMESTAMP()
格式化:
DATE_FORMAT(NOW(),'%Y-%m-%d') 结果:2021-01-15
DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i:%S') 结果:2021-01-15 13:35:40
其它:
now()--取当前时间
SQLSERVER:
select day(createtime) from life_unite_product --取时间字段的天值
select month(createtime) from life_unite_product --取时间字段的月值
select year(createtime) from life_unite_product --取时间字段的年值
select datepart(yy,createtime) from life_unite_product --取时间字段的年值
select datepart(qq,createtime) from life_unite_product --取时间字段的季度值
select datepart(mm,createtime) from life_unite_product --取时间字段的月值
select datepart(dy,createtime) from life_unite_product --取时间字段是那年的第几天
select datepart(dd,createtime) from life_unite_product --取时间字段的天值
select datepart(wk,createtime) from life_unite_product --取时间字段是那年的第几个星期
select datepart(dw,createtime) from life_unite_product --取时间字段是那年的那个星期的第几个工作日(工作日从星期日开算)
select datepart(hh,createtime) from life_unite_product --取时间字段的小时值
select datepart(mi,createtime) from life_unite_product --取时间字段的分钟值
select datepart(ss,createtime) from life_unite_product --取时间字段的秒值
select datepart(ms,createtime) from life_unite_product --取时间字段的毫秒值
select dateadd(yy,-1,createtime) from life_unite_product ----取时间字段(年份被减1了)
select dateadd(mm,3,createtime) from life_unite_product ----取时间字段(月份被加3了)
select dateadd(dd,1,createtime) from life_unite_product ----取时间字段(日被加1了)
select DATEDIFF(yy,createtime,getdate()) from life_unite_product --与当前日期的年份差
select DATEDIFF(mm,createtime,getdate()) from life_unite_product --与当前日期的月份差
select DATEDIFF(dd,createtime,getdate()) from life_unite_product --与当前日期的日数差
select DATEDIFF(mi,createtime,getdate()) from life_unite_product --与当前日期的分钟数差
select datename(yy,createtime) from life_unite_product --取时间字段的年值
select datename(mm,createtime) from life_unite_product --取时间字段的月值
select datename(dd,createtime) from life_unite_product --取时间字段的天值
select getdate() --取当前时间
select CONVERT(varchar(100), GETDATE(), 23);-- 格式化成 如2023-03-20
select CONVERT(varchar(100), GETDATE(), 8); -- 格式化成 如 13:22:22