Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2007
    Location
    010101010110100
    Posts
    803

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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 ...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Frank, take a look at the Date_Add() function
    George
    Home | Blog

  4. #4
    Join Date
    Mar 2007
    Location
    010101010110100
    Posts
    803
    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

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Mar 2007
    Location
    010101010110100
    Posts
    803
    Thanks for the link Rudy. That was exactly what I needed.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •