Connecting Tech Pros Worldwide Forums | Help | Site Map

Extract date from timestamp

priyan's Avatar
Member
 
Join Date: Aug 2007
Posts: 54
#1: Aug 8 '07
hi

I am having a startdate variable with timestamp datatype. I want to extract only the date from timestamp field........
Expand|Select|Wrap|Line Numbers
  1. select extract('hour' from timestamp '2001-02-16 20:38:40') 
  2.  
this query extracts hour from the input in the same way is there any option for extracting only date.

Please help as soon as possible.

Moderator
 
Join Date: Nov 2006
Location: Boston, USA
Posts: 505
#2: Aug 10 '07

re: Extract date from timestamp


Try this:
Expand|Select|Wrap|Line Numbers
  1. postgres=# SELECT date ('2001-02-16 20:38:40');
  2.     date
  3. ------------
  4.  2001-02-16
  5. (1 row)
  6.  
  7. postgres=# SELECT '2001-02-16 20:38:40'::date;
  8.     date
  9. ------------
  10.  2001-02-16
  11. (1 row)
  12.  
priyan's Avatar
Member
 
Join Date: Aug 2007
Posts: 54
#3: Aug 11 '07

re: Extract date from timestamp


Quote:

Originally Posted by michaelb

Try this:

Expand|Select|Wrap|Line Numbers
  1. postgres=# SELECT date ('2001-02-16 20:38:40');
  2.     date
  3. ------------
  4.  2001-02-16
  5. (1 row)
  6.  
  7. postgres=# SELECT '2001-02-16 20:38:40'::date;
  8.     date
  9. ------------
  10.  2001-02-16
  11. (1 row)
  12.  

thank you for helping me
Reply