Solved

date_trunc(week,timestamp) not working in postgresql 7

Posted on 2006-11-01
2
1,070 Views
Last Modified: 2008-02-01
The following query

select  date_trunc(week,timestamp)

retrieves the start_date of the current week as timestamp ,

2006-10-10 00:00:00

It works in postgresql 8. But fails in postgresql 7.
Let me know the postgresql query which retrieves first date of a week (compatible in both postgresql 7 and 8 versions)
0
Comment
Question by:shathy
2 Comments
 

Author Comment

by:shathy
ID: 17848878
The following query

select  date_trunc(week,timestamp)

retrieves the start_date of the current week as timestamp ,

2006-10-10 00:00:00

It works in postgresql 8. But fails in postgresql 7.
Let me know the postgresql query which retrieves first date of a week (compatible in both postgresql 7 and 8 versions)
0
 
LVL 22

Accepted Solution

by:
earth man2 earned 500 total points
ID: 17862041
=> select current_timestamp::date - ( 5 + to_number( to_char( current_timestamp, 'D' ),'9' )::int ) % 7;
  ?column?  
------------
 2006-10-30
(1 row)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: http://www.postgresql.org/ (http://www.postgresql.org/) This requires some add-o…
Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question