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)
精彩评论