Solved

What is the equivalent date function in postgreSQL for add_months or DateAdd

Posted on 2007-12-06
3
3,448 Views
Last Modified: 2012-05-05
I am looking for the syntax for the date function that works like dateadd in sql server that I can use in PostgreSQL.

0
Comment
Question by:Brian_Sutherland
[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
3 Comments
 
LVL 10

Expert Comment

by:ivanovn
ID: 20422779
You could use the overloaded arithmetic in PostgreSQL to achieve the same result. For example if you wanted to add one day to a given date you would do something similar to the code below.

Read http://www.postgresql.org/docs/8.2/interactive/functions-datetime.html for more info.

date '2007-12-06' + interval '1 day'

Open in new window

0
 

Author Comment

by:Brian_Sutherland
ID: 20423068
Thanks, what if I had a column called term that held  the number of months I want to add?
Would it be:
<date filed> + interval '<term> months'  


0
 
LVL 22

Accepted Solution

by:
earth man2 earned 50 total points
ID: 20424549
date_col + term_col * interval '1 months'
0

Featured Post

Webinar: MariaDB® Server 10.2: The Complete Guide

Join Percona’s Chief Evangelist, Colin Charles as he presents MariaDB Server 10.2: The Complete Guide on Tuesday, June 27, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

707 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