Time Calculation

Results 1 to 3 of 3

Thread: Time Calculation

  1. #1
    Join Date
    Dec 1969

    Default Time Calculation

    I am using SQL 7, and I have several datetime fields. The first on is the 'Start Time'. How could I set the others based on the first one. Example, if I entered 4:00:00 PM 1/1/2003 into Start Time, how could I get Timefield2 to be Start Time + 30 minutes?

  2. #2
    Join Date
    Dec 1969

    Default use DateADD

    SELECT DATEADD(minute, 30, YourStartTimeField) AS SecondTimeInterval FROM yourTable<BR><BR>Check out the online Documentation for SQL7.0... They give a good explaination of the date functions<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default But that doesn't work...

    ...in the middle of an INSERT statement.<BR><BR>That is, you can&#039;t do something like:<BR><BR>INSERT INTO table (time1, time2) VALUES(&#039;3:30 PM&#039;, DateAdd(&#039;n&#039;,30,time1) )<BR><BR>I don&#039;t think you can have one field&#039;s value depend on the just-inserted value of another field. No? Yes?<BR><BR>So you&#039;d have to do it in two steps:<BR><BR>INSERT INTO table (time1, time2) VALUES(&#039;3:30 PM&#039;, NULL )<BR>UPDATE table SET time2 = DateAdd(&#039;n&#039;,30,time1) WHERE id=@@IDENTITY<BR><BR>or something like that, no?<BR><BR><BR>

Posting Permissions

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