How to write a postgresql query for getting only the date part of timestamp field, from a table
You can use date(t_stamp) to get only the date part from a timestamp. Extracts the date part of the date or datetime expression expr.
PostgreSQL timestamp example First, create a table that consists of both timestamp the timestamptz columns. Next, set the time zone of the database server to America/Los_Angeles . After that, query data from the timestamp and timestamptz columns. The query returns the same timestamp values as the inserted values.
In MySQL, use the DATE() function to retrieve the date from a datetime or timestamp value. This function takes only one argument – either an expression which returns a date/datetime/ timestamp value or the name of a timestamp/datetime column. (In our example, we use a column of the timestamp data type.)
select DATE(my_field) from my_table;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With