?
Solved

date_trunc(week,timestamp) not working in postgresql 7

Posted on 2006-11-01
2
Medium Priority
?
1,124 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month10 days, 2 hours left to enroll

762 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