If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
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, 07:37
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
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
Reply With Quote
  #2 (permalink)  
Old 10-17-07, 08:16
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 10-17-07, 08:17
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Frank, take a look at the Date_Add() function
__________________
George
Twitter | Blog
Reply With Quote
  #4 (permalink)  
Old 10-17-07, 08:32
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
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
Reply With Quote
  #5 (permalink)  
Old 10-17-07, 09:29
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 10-17-07, 18:27
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Thanks for the link Rudy. That was exactly what I needed.

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

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