Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > MySQL > How to calculate a date and a whole number

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-17-07, 08:37
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 706
How to calculate a date and a whole number

Hi all,

I have a table holding contractual data such as the date the contract was signed, the term of the contract as well as other data. I was wondering if it was possible to calculate the expiration date using the number of months that the contract is valid plus the contract start date.

If this is possible, can someone please tell me what type of query I would need to use? The two relevant fields are:

term (int)
start_date (date)

Sample data:
Code:
term start_date 4 2007-12-03 2 2007-10-08 6 2007-03-01

The first contract would expire 2008-04-03 and so on..

What I would like to do is get the current status of the contract by using this formula. Is this possible or should I add another column for the end_date?

Thanks,

Frank
__________________
I and many others around the world are of the strong belief that the universe was created by the Flying Spaghetti Monster. It was He who created all that we see and all that we feel. We feel strongly that the overwhelming scientific evidence pointing towards evolutionary processes is nothing but a coincidence, put in place by Him.
Reply With Quote
  #2 (permalink)  
Old 10-17-07, 09:16
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,554
yes, it's possible, the type of query you want is a SELECT
Code:
select date_add(start_date, interval term month) as end_date ...
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #3 (permalink)  
Old 10-17-07, 09:17
georgev georgev is offline
SQL Apprentice
 
Join Date: Jan 2007
Location: hiding
Posts: 8,139
Frank, take a look at the Date_Add() function
__________________
George
You only stop learning when you stop asking questions.
Reply With Quote
  #4 (permalink)  
Old 10-17-07, 09:32
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 706
Rudy, Georgie.. Thanks. That was too easy..

Is there a cheat sheet or something I can reference with regard to mysql functions? Like a quick reference? I know I can use the mysql site but sometimes it is like looking for a needle in a haystack especially if I'm not really sure what I need.

Thanks again guys!

Frank
__________________
I and many others around the world are of the strong belief that the universe was created by the Flying Spaghetti Monster. It was He who created all that we see and all that we feel. We feel strongly that the overwhelming scientific evidence pointing towards evolutionary processes is nothing but a coincidence, put in place by Him.
Reply With Quote
  #5 (permalink)  
Old 10-17-07, 10:29
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,554
Quote:
Originally Posted by fjm1967
Is there a cheat sheet or something I can reference with regard to mysql functions?
here's what i use: http://phlab.net/myman/

the mysql site search feature stinks
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #6 (permalink)  
Old 10-17-07, 19:27
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 706
Thanks for the link Rudy. That was exactly what I needed.

__________________
I and many others around the world are of the strong belief that the universe was created by the Flying Spaghetti Monster. It was He who created all that we see and all that we feel. We feel strongly that the overwhelming scientific evidence pointing towards evolutionary processes is nothing but a coincidence, put in place by Him.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On