当前位置:Gxlcms > 数据库问题 > postgresql 截取日期字符串 的函数

postgresql 截取日期字符串 的函数

时间:2021-07-01 10:21:17 帮助过:13人阅读

SELECT now()::timestamp + ‘1 month‘;  --当前时间加一个月 SELECT now()::timestamp + ‘1 day‘;  --当前时间加一天 SELECT now()::timestamp + ‘1 hour‘;  --当前时间加一个小时 SELECT now()::timestamp + ‘1 min‘;  --当前时间加一分钟 SELECT now()::timestamp + ‘1 sec‘;  --加一秒钟 select now()::timestamp + ‘1 year 1 month 1 day 1 hour 1 min 1 sec‘;  --加1年1月1天1时1分1秒 SELECT now()::timestamp + (col || ‘ day‘)::interval FROM table --把col字段转换成天 然后相加

 

 

 

 

 

 

7.按日期查询的方法

Timestamp without timezone

方法一:

select * from user_info where create_date >= ‘2015-07-01‘ and create_date < ‘2015-08-15‘;

方法二:为啥字符串可以按日期格式比较大小

select * from user_info where create_date

between ‘2015-07-01‘ and ‘2015-08-15‘;

方法三:

select * from user_info where create_date >= ‘2015-07-01‘::timestamp and create_date < ‘2015-08-15‘::timestamp;

方法四:

select * from user_info where create_date between to_date(‘2015-07-01‘,‘YYYY-MM-DD‘) and to_date(‘2015-08-15‘,‘YYYY-MM-DD‘);

 

 

 

 

 

 

 

 

 

 

8.显示序号   

 select (ROW_NUMBER () OVER (ORDER BY bb.SUM DESC)) AS xuhao from tb_person

9.获取日期 将01-01前的0 去掉

map.get("score_date").toString().substring(8).replaceFirst("^0*", "") ;

10.获取系统当前月的每天的日期

SELECT
generate_series ( date_trunc( ‘month‘, to_date( to_char( NOW(), ‘YYYY-MM-DD‘ ), ‘YYYY-MM-DD‘ )) :: DATE, NOW() :: DATE, ‘1 day‘ ) :: DATE AS datetime

结果如下:

技术图片

 

 

 

 

 

 

 

 

 

 

 

11.保留7天的日期

delete from  表名  where date_created <(now()-interval ‘7 day‘)

postgresql 截取日期字符串 的函数

标签:sql   timestamp   str   alt   core   color   时间   width   mes   

人气教程排行