Solved

date_trunc(week,timestamp) not working in postgresql 7

Posted on 2006-11-01
2
1,092 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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