Creating a table with a date field

Results 1 to 2 of 2

Thread: Creating a table with a date field

  1. #1
    Join Date
    Dec 1969

    Default Creating a table with a date field

    Hello there,<BR><BR>I&#039;m trying to create a table using "local packages" within MS -SQL7.0. The idea is that I want to take the results of one table, and create another table, but whilst doing that -execute a calculation that minuses one date form another (the date today)<BR><BR>Heres the code: <BR><BR>"SELECT UserID, TitleID, FirstName, EmailAddress, CombinedDate, <BR>EmailSent, TotalOutStanding <BR>INTO Emails <BR>FROM UserProfile"<BR><BR>Now i want to be able to create another column in the table called "Days" which will be calculated as follows : <BR><BR>CombinedDate(another date) - GetDate(... the date now ) = Days<BR><BR>Would I use the DateDiff command? Any advise would be appreciated !<BR><BR>Roger

  2. #2
    Join Date
    Dec 1969

    Default Yes, use DateDiff...

    ...but be aware of a bug lurking to happen.<BR><BR>If you do DateDiff(d,someDateTime,getDate()) you might be off by a day. Reason: getDate() returns a date *and* time. So if it is no 9:00AM and the value in the someDateTime field is 11:00PM yesterday, you will get zero days as the DateDiff. The exact cutoff point probably depends on whether DateDiff rounds or truncates (and I don&#039;t know). You *might* want to, instead, get the number of seconds difference, divide by seconds per day, and then "round up" (or not!) to control things more closely.<BR><BR>Experiment!<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