SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2001
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I automatically calculate the difference between two dates?

    Before you yell, I know I am cross-posting, but I guess this question relates to both ASP and SQL.

    I am building a database that users will update.
    I have a table named "products".
    Every product has a shelf life of 3 years and expires exactely at the end of the 3rd year.
    Here is my table:
    Productid ---- int
    productName ---- varchar
    manufacture_date ----- datetime default (getdate)
    Expire_date ----- datetime

    What I want is this, whenever a product is entered, the defualt date is the date the entry
    was made. (I am using the "getdate") to automatically grab this.
    BUT I also want the "Expire_date" field automatically calculated and then filled in.
    That is, a user enters a product "manufacture_date" as 05/22/2003,
    Then I want the expire field to be filled with 05/22/2006.
    My preference is to handle this on the DB site and not ASP.

    I am usings ASP and MS SQL 7.
    Thanks,
    assigned

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DATEADD ( datepart , number, date ) ?

  3. #3
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this nice or what?
    Guess what the result from this is?
    select dateadd(year, 3, '2004-02-29')


    Exactly: '2007-02-28', not '2007-02-29' or '2007-03-01'


Bookmarks

Posting Permissions

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