1

The query below returns a table with data type time stamp without time zone. How do I format this query so it removes the timestamp and just save the date?

SELECT * 
FROM dblink('dbname=mydb', 'select startdate from study') as t1(start timestamp without time zone);

Output:

|-----------start-------|   
|  2012-03-19 00:00:00  |  
|  2012-04-26 00:00:00  |  
|  2012-05-01 00:00:00  |  
|  2012-06-01 00:00:00  |  
|  2012-07-01 00:00:00  |  
|  2012-08-01 00:00:00  |  
|  2012-02-07 00:00:00  |  
|  2012-04-26 00:00:00  |  
|  2012-09-01 00:00:00  |  
|  2012-12-01 00:00:00  |  
|  2013-11-11 00:00:00  |  
+-----------------------+ 

What I'm looking for:

|------start---|
|  2012-03-19  |  
|  2012-04-26  |  
|  2012-05-01  |  
|  2012-06-01  |  
|  2012-07-01  |  
|  2012-08-01  |  
|  2012-02-07  |  
|  2012-04-26  |  
|  2012-09-01  |  
|  2012-12-01  |  
|  2013-11-11  |  
Michael Bui
  • 190
  • 2
  • 12

1 Answers1

0

You need to cast timestamp field to date, following ways can be apply

SELECT * 
FROM dblink('dbname=bhkpps', 'select begins::date from study') as t1(start date);

or

SELECT * 
FROM dblink('dbname=bhkpps', 'select begins from study') as t1(start date);

or

SELECT start::date
FROM dblink('dbname=mydb', 'select begins from study') as t1(start timestamp without time zone);
Vivek S.
  • 19,945
  • 7
  • 68
  • 85