sql - Conditional querying to return timestamp if NOT todays date , else return time -


i have sql query want retrieve timestamp records table.

the query must return time without time zone if todays date = timestamp in record.

if record's timestamp::date not equals todays date return timestamp. examples:

2013-08-07 18:00:18.692+01 2013-08-09 20:13:09.927+01 

expected result:

18:00:18.692  2013-08-09 20:13:09.927+01 

from 2 timestamps able retrieve time 1st todays date retrieve both date , time second not todays date

this formatting issue, might better handle in application code. can in sql.

create table t (   ts timestamp not null   );  insert t values  ('2013-01-01 08:00'); insert t values  (current_timestamp); 

the time , timestamp data types aren't compatible in way want return them, casting text makes sense.

select case when ts::date = current_date ts::time::text             else ts::text        end t;  ts -- 2013-01-01 08:00:00 16:34:52.339 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -