[pgsql]pgsql数据库时间函数
来源:互联网 发布:ubuntu 怎么进入u盘 编辑:程序博客网 时间:2024/04/30 06:30
1.获取系统时间函数
select now(); --2012-05-12 18:51:59.562+08
select current_timestamp; --2012-05-12 18:52:12.062+08
select current_date; --2012-05-12
select current_time; --18:53:23.234+08
2.时间的计算
--使用interval
select now()+interval '2 day'; --2012-05-14 20:05:32.796+08 2天后
select now()-interval '2 day'; --2012-05-10 20:07:23.265+08 2天前
select now()+interval '2 hour'; --2012-05-12 22:06:38.375+08 2小时后
....
interval可以不写,其值可以是
Abbreviation Meaning
Y Years
M Months (in the date part)
W Weeks
D Days
H Hours
M Minutes (in the time part)
3.时间的截取
--使用extract extract(interval,timestamp);
select extract(year from now()); --2012
select extract(mon from now()); --5 5月份
...
interval值参考上面
4.时间的转换
select timestamp '2012-05-12 18:54:54'; --2012-05-12 18:54:54
select date '2012-05-12 18:54:54'; --2012-05-12
select time '2012-05-12 18:54:54'; --18:54:54
select TIMESTAMP WITH TIME ZONE '2012-05-12 18:54:54'
--2012-05-12 18:54:54+08
--与unix时间戳的转换
SELECT TIMESTAMP 'epoch' + 1341174767 * INTERVAL '1 second';
--2012-07-01 20:32:47
参考:http://my.oschina.net/Kenyon/blog/57188
select now(); --2012-05-12 18:51:59.562+08
select current_timestamp; --2012-05-12 18:52:12.062+08
select current_date; --2012-05-12
select current_time; --18:53:23.234+08
2.时间的计算
--使用interval
select now()+interval '2 day'; --2012-05-14 20:05:32.796+08 2天后
select now()-interval '2 day'; --2012-05-10 20:07:23.265+08 2天前
select now()+interval '2 hour'; --2012-05-12 22:06:38.375+08 2小时后
....
interval可以不写,其值可以是
Abbreviation Meaning
Y Years
M Months (in the date part)
W Weeks
D Days
H Hours
M Minutes (in the time part)
3.时间的截取
--使用extract extract(interval,timestamp);
select extract(year from now()); --2012
select extract(mon from now()); --5 5月份
...
interval值参考上面
4.时间的转换
select timestamp '2012-05-12 18:54:54'; --2012-05-12 18:54:54
select date '2012-05-12 18:54:54'; --2012-05-12
select time '2012-05-12 18:54:54'; --18:54:54
select TIMESTAMP WITH TIME ZONE '2012-05-12 18:54:54'
--2012-05-12 18:54:54+08
--与unix时间戳的转换
SELECT TIMESTAMP 'epoch' + 1341174767 * INTERVAL '1 second';
--2012-07-01 20:32:47
参考:http://my.oschina.net/Kenyon/blog/57188
0 0
- [pgsql]pgsql数据库时间函数
- pgsql 时间函数的方法
- pgsql数据库和PHP中日期、时间戳处理函数
- PGSQL 数据库
- pgsql
- pgsql日期及时间
- pgsql 时间sql
- pgsql 数据库恢复备份
- pgsql其他数据库对象
- pgsql操作数据库命令
- pgsql还原数据库
- PGSQL 重建索引 函数
- pgsql字符串函数
- pgsql聚集函数
- pgsql命令行查询所有数据库
- 远程连接pgsql数据库常用命令
- PGSQL下的常用函数
- pgsql函数和操作符
- STL源码剖析之【二分查找】
- Android 基于Netty的消息推送方案之概念和工作原理(二)
- signal与定时器
- Eclipse启动时f出现ail to create Java Virtual Machine问题的解决
- C#基础-----虚方法实现多态
- [pgsql]pgsql数据库时间函数
- Android 基于Netty的消息推送方案之字符串的接收和发送(三)
- 查看可执行程序的依赖库
- Js获取当前日期时间及其它操作
- 不使用UIImagePickerControllerOriginalImage获取相册图片
- MongoDB常用命令
- 九度1012畅通工程(并查集)
- Android 基于Netty的消息推送方案之对象的传递(四)
- Oracle函数-计算时间跨度