取当前日期的函数:

(1)       取当前时间:select now()

(2)       取当前时间的日期: select current_date

(3)       取当前具体时间(不含日期) select current_time

时间的加减:

Select now()

(1)     取三天后的时间:select now() + interval ‘3 day’;

(2)     取三天前的时间:select now() - interval ‘3 day’

(3)     取1小时后(前)时间: select now() +(-) interval ‘ 1 hour’

(4)     取10分钟后(前)时间:select now() +(-) interval ‘ 10 minutes’

取时间字段的部分值:年份,月份,日…  函数:extract(field from source):field表示要取的时间对象,source表取得时间来源,其类型需为timestamp

(1)     取年份: select extract (year from now())

(2)     取月/day/hour/minute/… : select extract(month/day/hour/minute from now()); select extract(day from timestamp‘2015-11-20’)

(3)     取目前所在星期: select extract(week from now());

Timestamp 类型:

Time , interval, timestamp 可以指定精度,精度范围0-6,定义格式参手册。

对于带时区timestamp 类型,select now() at  time zone ‘时区’,可去当地时间:

select now() at time zone 'GFT';--取法国时间

PS:关于带时区与不带时区的区别,可参考http://francs3.blog.163.com/blog/static/40576727201153014258289/

(1)     查询 current_timestamp : select current_timestamp

可以看到current_timestamp 返回的是带时区(+08)时间类型,精度为643549。

(2)     去掉精度

(3)     去掉时区

另一种写法:

(4)     用case()函数进行类型转换。

Select cast(current_timestamp(0) as timestamp without time zone)

(5)     对精度进行对比可以看到(p)是精度

Select current_timestamp(2)::timestamp without time zone

Select current_timestamp(6)::timestamp without time zone

PostgreSQL中的时间操作总结的更多相关文章

  1. JAVA中的时间操作

    java中的时间操作不外乎这四种情况: 1.获取当前时间 2.获取某个时间的某种格式 3.设置时间 4.时间的运算 好,下面就针对这四种情况,一个一个搞定. 一.获取当前时间 有两种方式可以获得,第一 ...

  2. PostgreSQL中的 时间格式转化常识

    下面的SQL文查询结果是 "2018-08-20 10:09:10.815125",并且返回类型可以当String处理.返回json等都方便使用. SQL> SELECT t ...

  3. Robot Framework:RF中对时间操作的datetime库常用关键字

    [转自:http://blog.csdn.net/r455678/article/details/52993765] 1.对固定日期进行操作,增加或减去单位时间或者时间段 2.对两个时间段进行操作 3 ...

  4. 【转】 robotframework(rf)中对时间操作的datetime库常用关键字

    转自http://blog.csdn.net/r455678/article/details/52993765 DateTime库是robotframework内置的库 1.对固定日期进行操作,增加或 ...

  5. robotframework(rf)中对时间操作的datetime库常用关键字

    1.对固定日期进行操作,增加或减去单位时间或者时间段 2.对两个时间段进行操作 3.对时间格式转化,获取时间戳. 4.从完整时间中取指定年月日等 5.对时间类型进行格式化 6.获取当前时间或者指定时区 ...

  6. Oracle中对时间操作的一些总结

    sysdate+(5/24/60/60) 在系统时间基础上延迟5秒 sysdate+5/24/60 在系统时间基础上延迟5分钟 sysdate+5/24 在系统时间基础上延迟5小时 sysdate+5 ...

  7. PostgreSQL 中日期类型转换与变量使用及相关问题

    PostgreSQL中日期类型与字符串类型的转换方法 示例如下: postgres=# select current_date; date ------------ 2015-08-31 (1 row ...

  8. java时间操作

    这篇讲的也很专业:http://soft.zdnet.com.cn/software_zone/2007/1129/660028.shtml java中的时间操作不外乎这四种情况: 1.获取当前时间 ...

  9. //四舍五入//得到倒序//比较字符串//拦截时间,实现超时锁屏//判断是否越狱//配置PodFile//Storyboard中跳转操作//处理不可逆的push界面操作

    //处理不可逆的push界面操作 VerifyRealNameViewController *verifyRealNameCtrl = [VerifyRealNameViewController vi ...

随机推荐

  1. Android成长日记-WebView使用

    在App中有时候会看到一些页面是以网页的形式展示,其原理就是运用了WebView,下面予以讲述WebView 1. 使用Intent调用系统浏览器或者第三方浏览器打开网页 调用系统浏览器打开页面 Ur ...

  2. Linux.BackDoor.Chikdos/Elknot Attack And Defense Analysis

    catalogue . 恶意程序概述 . 模块分解 . 通信协议 . 木马清理 1. 恶意程序概述 Trojan.Chikdos.A是一个木马,它允许远程攻击者利用受感染计算机发动DDoS攻击 . 木 ...

  3. Linux File System Change Monitoring Technology、Notifier Technology

    catalog . 为什么要监控文件系统 : hotplug . udev . fanotify(fscking all notification system) . inotify . code e ...

  4. RabbitMQctl命令

    RabbitMQControl RabbitMQ提供了可视化的网页供我们进行一些配置与操作,但是ctl的命令比UI来的专业的多,一些UI无法完成的操作就需要使用ctl命令来进行处理了 这里是官方的文档 ...

  5. Unity3d5.0 新UI之2048

    因为汽车系统没写出来所以,纠结之中,弄了弄新版本的UI. 做了个2048. 新版本的unity的UI必须以Canvas为基底来呈现,如果没有加画布的话可是显示不出来东西的哦. 而且作为UI上的所有组件 ...

  6. C# 字符串处理

     1.比较字符串 String 类提供了一系列的方法用于字符串的比较,如CompareTo 和 Equals方法等. ① CompareTo : 如果参数的值与此实例相等,则返回0:如果此实例大于参数 ...

  7. wildfly jsf 文件 上传后 可以下载 访问

    // String aa = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath(); // lo ...

  8. iOS - 基础面试知识

    1.arc(automatic reference counting) OC对象被创建时引用计数从默认值0加1,当它被释放时候引用计数减1,引用计数减0时autorelease方法,销毁OC对象. 自 ...

  9. 【项目】'NSRangeException', reason: '*** -[__NSArrayM removeObjectAtIndex:]: index 2 beyond bounds [0 .. 1]'

    问题代码: [self.assetsArray objectAtIndex:indexPath.row] 问题解决思路:这里

  10. uC/OS-II时间(OS_time)块

    /*************************************************************************************************** ...