Solved

Calculate Working Days between dates

Posted on 2010-11-12
2
1,962 Views
Last Modified: 2012-05-10
Hello Experts,

I am working on a Postgres DB that gets populated with data from Excel files.
In this DB I have a table with some columns with a type of timestamp without time zone
like: Creation_Date_UTC and Closure_date_UTC

What I want is maybe a function able to calculate "Working Days" (Bussines days <Monday to Friday>) from the interval in those two columns (or others I specify in the query).

ie: get_working_days(Creation_Date_UTC, Closure_date_UTC)

My date format in postgres is DD/MM/YYYY.

Thanks so much!
0
Comment
Question by:daniel_spiri
[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
 
LVL 7

Accepted Solution

by:
Hatrix76 earned 500 total points
ID: 34125433
CREATE OR REPLACE FUNCTION get_working_days (in date, in date) RETURNS int8 AS
$BODY$
SELECT count(*) FROM
(SELECT extract('dow' FROM $1+x) AS dow
FROM generate_series(0,$2-$1) x) AS foo
WHERE dow BETWEEN 1 AND 5;
$BODY$
LANGUAGE 'sql'
GO


best,

ray
0
 

Author Closing Comment

by:daniel_spiri
ID: 34127303
Thanks!
0

Featured Post

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

724 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