Re: Get date timestamp(3) without time zone column - PGSQL 9.5

From: Sameer Kumar <sameer(dot)kumar(at)ashnik(dot)com>
To: Patrick B <patrickbakerbr(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Get date timestamp(3) without time zone column - PGSQL 9.5
Date: 2016-09-05 03:06:07
Message-ID: CADp-Sm51d3B2oSNj5kCAA5_SiQ0HQLoMrshjfO-g2xCzJs7Saw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Sep 5, 2016 at 10:59 AM Patrick B <patrickbakerbr(at)gmail(dot)com> wrote:

> Hi guys,
>
> I got the tasks table that has the tasks_start column:
>
>> tasks_start | timestamp(3) without time zone
>
>
>
> select tasks_start from tasks LIMIT 1;
>
>> tasks_start
>> -------------------
>> 2016-08-10 00:30:00
>
>
> I'm trying to cast the date, using this query:
>
>> SELECT cast(tasks_start as date) FROM "jobs" WHERE "tasks"."deleted" =
>> 'f' AND "tasks"."recurrence_id" = 1 AND (Date(tasks_start) in ('2016-08-10')
>
>
You might want to share the version of PostgreSQL you are using.

You might want to try date_trunc and AT TIMEZONE function/operators-

https://www.postgresql.org/docs/9.4/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC

SELECT date_trunc('day', tasks_start at TIME ZONE 'EST')

Note: I have not tried this statement

Is this something you are going to use often? If that is the case then
consider to re-model your query. The moment you use an expression on a
column it would not use a normal BTree index.

> but it doesn't work.. I get 0 rows... what am I doing wrong?
>
> cheers
> Patrick
>
--
--
Best Regards
Sameer Kumar | DB Solution Architect
*ASHNIK PTE. LTD.*

101 Cecil Street, #11-11 Tong Eng Building, Singapore 069 533

T: +65 6438 3504 | M: +65 8110 0350

Skype: sameer.ashnik | www.ashnik.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Patrick B 2016-09-05 03:17:46 Re: Get date timestamp(3) without time zone column - PGSQL 9.5
Previous Message Patrick B 2016-09-05 02:57:50 Get date timestamp(3) without time zone column - PGSQL 9.5