Обсуждение: add or subtract days from a 'date' in query

Поиск
Список
Период
Сортировка

add or subtract days from a 'date' in query

От
bubola
Дата:
hi all!

I'm quite new to pgsql, but I tried to read as much docs as I could, and
also tried to browse the ml archive here, without useful results until now.

So I hope you will excuse me for the following question, that I know must
appear quite tedious to the experts :))

I just need to add (or subtract) a certain number of days to a given date
(in the format yyyymmdd), but cannot find the right syntax.

I tried many ways, making a cast to date, or to timestamp, but nothing got
right
For instance, , cause I want the second date to be ten days more than the
1st, I started writing a query such as:

    insert into mytable (dateA, dateB)
        values
                ('mydateA', 'mydateA'+ 10)

but got an error msg, telling that I cannot add unknown type with int


so I made

        insert into mytable (dateA, dateB)
            values
                ('mydateA', 'mydateA'+ 10 days)

but pg did not understand what that 'days' stood for


so I tried


        insert into mytable (dateA, dateB)
                values
                    date('mydateA', 10)

and so on, but always with no result :((


Could anyone please help me?

Thanks a lot

        bubola

Re: add or subtract days from a 'date' in query

От
"D. Duccini"
Дата:
Try this:

 SET date = date + '1 month'::timespan

or '10 days'::timespan

-duck

On Sat, 23 Sep 2000, bubola wrote:

> hi all!
>
> I'm quite new to pgsql, but I tried to read as much docs as I could, and
> also tried to browse the ml archive here, without useful results until now.
>
> So I hope you will excuse me for the following question, that I know must
> appear quite tedious to the experts :))
>
> I just need to add (or subtract) a certain number of days to a given date
> (in the format yyyymmdd), but cannot find the right syntax.
>
> I tried many ways, making a cast to date, or to timestamp, but nothing got
> right
> For instance, , cause I want the second date to be ten days more than the
> 1st, I started writing a query such as:
>
>     insert into mytable (dateA, dateB)
>         values
>                 ('mydateA', 'mydateA'+ 10)
>
> but got an error msg, telling that I cannot add unknown type with int
>
>
> so I made
>
>         insert into mytable (dateA, dateB)
>             values
>                 ('mydateA', 'mydateA'+ 10 days)
>
> but pg did not understand what that 'days' stood for
>
>
> so I tried
>
>
>         insert into mytable (dateA, dateB)
>                 values
>                     date('mydateA', 10)
>
> and so on, but always with no result :((
>
>
> Could anyone please help me?
>
> Thanks a lot
>
>         bubola
>


-----------------------------------------------------------------------------
david@backpack.com            BackPack Software, Inc.        www.backpack.com
+1 651.645.7550 voice       "Life is an Adventure.
+1 651.645.9798 fax            Don't forget your BackPack!"
-----------------------------------------------------------------------------