PGSQL
毫秒值转换为年月
to_char(to_timestamp(createdtime/1000),'YYYY-MM')
毫秒值转换为年
to_char(to_timestamp(createdtime/1000),'YYYY')
毫秒值转换为年月日时分秒
to_char(to_timestamp(createdtime/1000),'YYYY-MM-DD HH:MI:ss')
毫秒值转换为周几
to_char(to_timestamp(createdtime/1000),'DAY')
详情见 Pgsql 官方手册
如查询每个月的工单分别有多少
select to_char(to_timestamp(createdtime/1000),'yyyy-MM') as "创建时间",count(workorderid) from workorder group by "创建时间";
MSSQL
通过year和month方法分别获取年和月,在字符串拼接在一起。
CAST(year(DATEADD(SECOND,operationtime/1000,'1970-1-1')) as varchar(4))+ '-'+CAST(month(DATEADD(SECOND,operationtime/1000,'1970-1-1')) as varchar(2)) as "变更时间"