开发者

Postgresql - query problem

开发者 https://www.devze.com 2023-03-09 17:15 出处:网络
I have a variable which is in this 开发者_运维问答format 2011-05-13. I want to make a query that adds one day to this variable and searches for days like this in the database.

I have a variable which is in this 开发者_运维问答format 2011-05-13. I want to make a query that adds one day to this variable and searches for days like this in the database.

I made this query but it doesnt work.

select phone from employee where date like (select date '2011-05-13' + 1) %

Can anyone help?


You need an INTERVAL:

SELECT phone FROM employee WHERE datefield = (date '2011-05-13' + INTERVAL '1 DAY') ;

Edit: Don't use LIKE when you're working with dates, there is no LIKE for a date.


Try the following:

SELECT phone FROM employee WHERE to_char(date, 'yyyy-mm-dd')::timestamp = ('2011-05-13'::timestamp + '1 day'::interval)
0

精彩评论

暂无评论...
验证码 换一张
取 消