PostgreSQL的时间函数使用整理
2013-07-27 14:49
459 查看
PG的时间函数使用整理如下
1.获取系统时间函数
2.时间的计算
--使用interval
3.时间的截取
--使用extract extract(interval,timestamp);
4.时间的转换
以上是基本的PG函数使用,可满足一般的开发运维应用
转自:/article/1873915.html
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
以上是基本的PG函数使用,可满足一般的开发运维应用
转自:/article/1873915.html
相关文章推荐
- PostgreSQL的时间函数使用
- PG的时间函数使用整理如下
- C/C++时间函数的使用
- 算法导论12.2-7 证明使用后继函数进行中序遍历的时间复杂度为Θ(n)
- 时间函数的使用。
- 43.Oracle数据库SQL开发之 日期和时间的存储与处理——使用时间值函数
- C/C++时间函数使用方法
- linux时间相关结构体和函数整理
- 一些时间系统函数整理
- C/C++时间函数使用方法
- postgreSQL格式化时间的函数详解
- c语言获取时间函数整理
- PostgreSQL的时间函数
- mysql 时间戳格式化函数from_unixtime使用说明
- C/C++时间函数的使用
- C++ 时间函数使用
- mysql 时间戳格式化函数from_unixtime使用说明
- 【转】MySQL时间函数的使用:查询本周、下周、本月、下个月份的数据
- JSP中有关时间和日期类的使用与JSP中的字符替换函数 str_replace()实现
- postgresql 游标,函数,存储过程使用例子