当前位置:网站首页>mysql和pgsql时间相关操作
mysql和pgsql时间相关操作
2022-04-23 06:04:00 【旺财2】
mysql时间操作
获取当前时间
select now();
2022-01-15 15:31:34.0
获取当前时间的前1天时间
select DATE_SUB(CURRENT_TIMESTAMP,INTERVAL 1 day);
可选值如下:
字符串转date
select str_to_date(DATE_SUB(now(),INTERVAL 0 day),'%Y-%m-%d %H:%i:%s');
时间格式化
select date_format(now(),'%Y-%m-%d %H:%i:%s');
pgsql时间操作
获取当前时间
select now();
2022-01-15 15:44:19.619571
获取当前时间的前1天时间
select now() - interval '1 day'
可选值如下:
时间格式化
select to_timestamp(now(),'yyyy-mm-dd hh24:mi:ss') - interval '1 day'
字符串转时间
to_timestamp('2022-01-22 00:00:00','yyyy-MM-dd hh24:mi:ss')
获取年月日时分秒
select extract(year from now()) || extract(month from now()),extract(day from now()),extract(hour from now()),extract(minute from now()),extract(second from now())
字符串截取
select substr(to_timestamp(now(),'yyyy-mm-dd hh24:mi:ss'),1,19)
版权声明
本文为[旺财2]所创,转载请带上原文链接,感谢
https://blog.csdn.net/wdyliuxingfeiyang/article/details/122510998
边栏推荐
- 关于我
- Thanos Compact组件测试总结(处理历史数据)
- 基于ECS搭建云上博客(体验有礼)
- BPF program of type XDP
- 异常记录-15
- Construire un blog Cloud basé sur ECS (bénédiction sur le Code Cloud Xiaobao, explication détaillée de la tâche iphone13 gratuite)
- 19C中ASM network未自动启动的处理
- Prometheus cortex Architecture Overview (horizontally scalable, highly available, multi tenant, long-term storage)
- Abnormal record-10
- ORACLE表有逻辑坏块时EXPDP导出报错排查
猜你喜欢
使用prom-label-proxy实现Prometheus Thanos的基于标签的多租户读
Thanos Compactor组件使用
Chaos带你快速上手混沌工程
Typical application scenarios of alicloud log service SLS
Winter combat camp hands-on combat - cloud essential environment preparation, hands-on practical operation, quickly build lamp environment, lead mouse cloud Xiaobao backpack without shadow
Introduction to DDoS attack / defense
Detailed explanation of RDMA programming
Dolphinscheduler配置Datax踩坑记录
基于ECS搭建云上博客(云小宝码上送祝福,免费抽iphone13任务详解)
ACFS文件系统创建扩大缩小等配置步骤
随机推荐
冬季实战营动手实战-上云必备环境准备,动手实操快速搭建LAMP环境 领鼠标 云小宝 背包 无影
Redis practice notes and source code analysis
Prometheus Thanos快速指南
BPF program of type XDP
try catch 不能捕获异步错误
Typical application scenarios of alicloud log service SLS
一个DG环境的ORA-16047: DGID mismatch between destination setting and target database问题排查及监听VNCR特性
Try catch cannot catch asynchronous errors
关于我
异常记录-18
Comparison between Prometheus thanos and cortex components
mysql和pg库遇到冲突数据时的两种处理方式
Prometheus的relabel_configs和metric_relabel_configs解释及用法示例
How does VirtualBox modify the IP network segment assigned to the virtual machine in the "network address translation (NAT)" network mode
[OSS file upload quick start]
Introduction to common APIs for EBFP programming
用Future与CountDownLatch实现多线程执行多个异步任务,任务全部完成后返回结果
How to use DBA_ hist_ active_ sess_ History analysis database history performance problems
BCC installation and basic tool instructions
Abnormal record-12