时间转换函数(年月日/年月/年)

来源:互联网 发布:数学必修三算法用学吗 编辑:程序博客网 时间:2024/05/19 14:02


[html] view plain copy
  1. //时间原本格式:1970-01-01 20:50:00
  2. where之后的条件为自定义添加
  3. //转换为年月日
  4. select substr(from_unixtime(unix_timestamp(时间字段名称,'yyyy-MM-dd')),1,4) as 自定义字段名称
  5. from table where id = * group by substr(from_unixtime(unix_timestamp(时间字段名称,'yyyy-MM-dd')),1,4);
  6. 显示:1970-01-01
  7. //转换为年月
  8. select substr(from_unixtime(unix_timestamp(时间字段名称,'yyyy-MM-dd')),1,4) as 自定义字段名称 
  9. from table where id = * group by substr(from_unixtime(unix_timestamp(时间字段名称,'yyyy-MM-dd')),1,7);
  10. 显示:1970-01
  11. //转换为年
  12. select substr(from_unixtime(unix_timestamp(时间字段名称,'yyyy-MM-dd')),1,4) as 自定义字段名称 
  13. from table where id = * group by substr(from_unixtime(unix_timestamp(时间字段名称,'yyyy-MM-dd')),1,10);
  14. 显示:1970

原创粉丝点击