Solved

date_trunc(week,timestamp) not working in postgresql 7

Posted on 2006-11-01
2
1,055 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
Comment Utility
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
Comment Utility
=> select current_timestamp::date - ( 5 + to_number( to_char( current_timestamp, 'D' ),'9' )::int ) % 7;
  ?column?  
------------
 2006-10-30
(1 row)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now