SQL Format of Date/Time

Results 1 to 4 of 4

Thread: SQL Format of Date/Time

  1. #1
    KdS Guest

    Default SQL Format of Date/Time

    I asked this question yesterday and received a partial answer. I am hoping that someone can be more specific. I am working in SQL 7 and I need to do a calculation on two datetime fields in the table to get a new "total" datetime field. I am not a SQL person, so I am having much trouble. I know to use the dateAdd or DateDiff function, but I would like to put it in the default value area instead of running a Select statement to make it work. Also, I want to get the complete datetime difference instead of just part (hh or yy etc..). Can this be done?

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default Not really sure what you are asking

    maybe an example will help.<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default Why SQL???

    I *think* that what this person wants is output like this:<BR><BR>starttime1 endtime1 difference1<BR>starttime2 endtime2 difference2<BR>...<BR>starttimeN endtimeN differenceN<BR>---------- -------- differenceTotal<BR><BR>Where only the starttime&#039;s and endtime&#039;s come out of DB fields and the differences and the sum of the differences are calculated.<BR><BR>KdS: Can you confirm/deny this? If I&#039;m wrong, can you show *WHAT* you are trying to do???<BR><BR>ANYWAY... Apparently he/she wants to try to do this all in SQL. No idea why, when it would be easier to do it in VBS code.<BR><BR>I have no idea how he/she is going to get the total (last line) with only one SQL query (I don&#039;t think it can be done), but the real problem is the he/she doesn&#039;t understand that if you get a difference in seconds you can easily transform seconds into hours and minutes by integer division and modulo. I guess he/she thinks there is some magic function that will let you do <BR>&nbsp; &nbsp; &nbsp; 15:30:25 minus 09:20:10 and get a result of 06:10:15<BR>Nope. No such thing. You have to do all the piddly little arithmetic yourself.<BR><BR>As for ADDING two datetime fields...That doesn&#039;t even make sense. What can it *POSSIBLY* mean to add<BR>&nbsp; &nbsp; &nbsp; 6 June 1999 plus 18 November 1972 ?????<BR><BR>So try to give examples, show the field names, show the table layout, etc. None of us seem to be able to decipher what you are asking, at this point.<BR><BR>

  4. #4
    Join Date
    Dec 1969

    Default DateTime Answer part III

    Now that you have added to your original question from yesterday and this afternoon (even though you have used a different post name) I have one more question.<BR><BR>If you are using MS SQL Server, have you even bothered to look in the "SQL Books Online?" There is a whole plethora of instructional information within on how to use not only MS-specific SQL, but basic T-SQL as well. It is not very hard to read and even comes with many relevant examples. Since you do not have a DBA, why don&#039;t you take it upon yourself to read this material if you have it.<BR><BR>If you would just show some of developmental code perhaps we could show you where the error lies. There is no magical, all-inclusive answer for every task you encounter. SQL is not as hard as it looks. Try scouring your resources, testing/re-testing your code, and posting it here for any help in between.<BR><BR>Good Luck,<BR><BR>Reginald

Posting Permissions

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