Re: subtracting from a date

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: subtracting from a date
Дата
Msg-id 52F3C6DA.6060902@gmail.com
обсуждение исходный текст
Ответ на subtracting from a date  (Jay Vee <jvsrvcs@gmail.com>)
Ответы Re: subtracting from a date  (Jay Vee <jvsrvcs@gmail.com>)
Список pgsql-general
On 02/06/2014 09:25 AM, Jay Vee wrote:
> I have reviewed working with dates documentation but some things are not
> clear and I cannot get an example to work for what I need.
>
> I am passing a date into a stored function like '2013-04-01'
>
> The stored function accepts this string as a date type.
>
> Within the function, I need to:
> 1.  subtract one year from this date into another date type
> 2.  subtract one month from this date into another date type
> 3.  subtract one day from this date into another date type
>
> Are there any examples of this?  This is not a timestamp type, but a
> date type.

Something like this:

test=> select '2013-04-01'::date - interval '1 yr';
       ?column?
---------------------
  2012-04-01 00:00:00
(1 row)

test=> select '2013-04-01'::date - interval '1 month';
       ?column?
---------------------
  2013-03-01 00:00:00
(1 row)

test=> select '2013-04-01'::date - interval '1 day';
       ?column?
---------------------
  2013-03-31 00:00:00


You did say what language you are using for the function so the
assignment will depend on that.

>
> thanks
>


--
Adrian Klaver
adrian.klaver@gmail.com


В списке pgsql-general по дате отправления:

Предыдущее
От: Jay Vee
Дата:
Сообщение: subtracting from a date
Следующее
От: Steve Crawford
Дата:
Сообщение: Re: subtracting from a date