首页 > 其他分享 >clickhouse时间日期函数

clickhouse时间日期函数

时间:2022-10-18 15:15:40浏览次数:75  
标签:-% 函数 Shanghai formatDateTime 日期 Asia 1665936000 toDateTime clickhouse

一、常用的时间戳到日期,日期到时间戳操作

SELECT toDateTime(1665936000,'Asia/Shanghai') `时间戳转为:%Y-%m-%d %H:%M:%S`,
       toUnixTimestamp('2022-10-17') AS `日期转为时间戳`,
       toDate(1665986835,'Asia/Shanghai') AS `时间戳转为天`,
       MINUTE(toDateTime(1665936000,'Asia/Shanghai')) AS `取分钟`,
       HOUR(toDateTime(1665936000,'Asia/Shanghai')) AS `取小时` ;

  结果示例:

 

 二、日期 formatDateTime 到`分钟、小时、天、月、周`的常用转换

SELECT formatDateTime(toDateTime(1665936000,'Asia/Shanghai'),'%Y-%m-%d %H:%M') AS `分钟`,
       formatDateTime(toDateTime(1665936000,'Asia/Shanghai'),'%Y-%m-%d %H') AS `小时`,
       formatDateTime(toDateTime(1665936000,'Asia/Shanghai'),'%Y-%m-%d') AS `天`,
       formatDateTime(toDateTime(1665936000,'Asia/Shanghai'),'%Y-%m') AS `月`,
       formatDateTime(toDateTime(1665936000,'Asia/Shanghai'),'%V') AS `周`,
       concat(cast(toMonday(toDateTime(1665936000,'Asia/Shanghai')) AS String),'**',cast(toMonday(toDateTime(1665936000,'Asia/Shanghai'))+6 AS String)) AS `周一到周日` ;

  结果示例:

 

 参考:https://clickhouse.com/docs/en/sql-reference/functions/date-time-functions/#formatdatetime

标签:-%,函数,Shanghai,formatDateTime,日期,Asia,1665936000,toDateTime,clickhouse
From: https://www.cnblogs.com/-courage/p/16802592.html

相关文章

  • 07.stm32最小系统版库函数点灯
    ......
  • SQL Server 函数大全
    表达式:是常量、变量、列或函数等与运算符的任意组合。以下参数中表达式类型是指表达式经运算后返回的值的类型字符串函数函数名称参数示例说明ascii......
  • JavaScript的日期对象的使用Date
    1<script>2letdate=newDate();//返回的是当前的时间3console.log(date.getFullYear());//获取的当前年份4console.log(date.getMonth()+1);......
  • OpenCV图像拼接函数vconcat()&hconcat()
        OpenCV图像直接拼接方法下面链接已做介绍,​​OpenCV常用图像拼接方法(一):直接拼接​​,只是这次我们将使用现成的函数实现,它们是vconcat()和hconcat(),当然也有一些......
  • OpenCV绘制标记函数drawMarker()
       OpenCV绘制标记函数drawMarker(),作用是在给定位置绘制一个标记,以OpenCV4.4.0为例:​​https://docs.opencv.org/4.4.0/d6/d6e/group__imgproc__draw.html#ga644c4a170......
  • 【C语言知识碎片】动态内存分配函数的使用
    1.为什么需要动态内存分配我们需要存储一些数据时可以创建一个变量或者数组来进行存储。intval=10;intarr[10]={0};数组在开辟好之后大小是不能变的,但是这种静态的内存在......
  • [答疑]商品有出厂日期,人有出生日期,这两个是ppt还是MI
    Derek2018-12-611:19老师,按照您课上说的,带有时间属性的类都可以看作是时刻时段类,假设商品有出厂日期,人有出生日期,这两个是ppt还是MI?潘加宇:带有时间属性的都是事件类,严格来......
  • vue + Reat 日期格式化
    可以在VUE和React上使用,将日期格式化xxxx年xx月xx日在VUE中需要放在filters中,使用方法:时间|formatTimeReact使用方式类似。filters:{formatTime:function(v......
  • python+clickhouse
    1.关于使用客户端能链接成功而使用代码无法访问clickhouse的问题clikchouse有两种链接方式:http端口默认为8123,tcp默认接口为9000使用客户端链接时用8123端口,而代码中就......
  • 常用PostgreSQL函数
    工作中用到的函数做一下记录加深影响。to_number用法:to_number(text1,text2)text1:需要转换的字符串text2:格式化模板,如模式9,代表一个数位......