getting date from timestamp in PostgreSQL

前端 未结 2 459
长发绾君心
长发绾君心 2021-02-18 14:22

I have a PostgreSQL timestamp as

2009-12-22 11:01:46

I need to change this to date as

2009-12-22

So that I ca

相关标签:
2条回答
  • 2021-02-18 14:40

    Cast it to date.

    SELECT yourtimestamp::date;
    

    If you need to extract other kinds of stuff, you might want to use EXTRACT or date_trunc

    Both links are to the same page, were you'll find more date/time-related functions.

    0 讨论(0)
  • 2021-02-18 15:06

    You can either use one of the Postgres date functions, such as date_trunc, or you could just cast it, like this:

    SELECT timestamp '2009-12-22 11:01:46'::date
    
    >>> 2009-12-22
    
    0 讨论(0)
提交回复
热议问题