Having trouble with Time in SQL Server 7.0

Results 1 to 3 of 3

Thread: Having trouble with Time in SQL Server 7.0

  1. #1
    Sam Pfanstiel Guest

    Default Having trouble with Time in SQL Server 7.0

    [4 in a series of unrelated (?) questions]<BR><BR>When I write a time to SQL 7.0 in a time/date field and then read the field into my ASP code, the result has a date in front of it (defaulting January 1, 1900). In Access 97 using ODBC, I never had any difficulty using a time/date field. Do I need to define a new data type in my database? Using this type of field for my date is working fine (it doesn&#039t display a default time).<BR><BR>Thanks for any help to any of my problems.

  2. #2
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: Having trouble with Time in SQL Server 7.0

    There is not a TIME datatype in SQL. The datatype is a DATETIME. Note the DATE in there! :) So, when you say to SQL, store 12:34 pm, SQL says, "What date do you want?" Of course you&#039ve not told SQL, you&#039ve moved onto other things. So SQL assumes you mean the earliest date he knows of, January 1, 1900. This is no biggie, and don&#039t worry about this if all you need is the time and not date.<BR><BR>To get JUST the time back, do the following:<BR><BR>Dim myTime<BR>myTime = objRS("SomeTime")<BR><BR>&#039Now, if you do Response.Write myTime, you&#039ll see the date.<BR>&#039We don&#039t want that.<BR>&#039So, we&#039re going to use the FormatDateTime function!! :)<BR>Response.Write FormatDateTime(myTime,4)<BR><BR>This should display the time field in a 24 hour format. See http://help.activeserverpages.com/iishelp/VBScript/htm/vbs109.htm for technical info on the FormatDateTime function.<BR><BR>What I strongly suggest is that you check out this customizable date formatting function, available at http://www.4guysfromrolla.com/webtech/112098-2.shtml. This also allows you to custom format your time in a number of ways.<BR><BR>Have a great day!

  3. #3
    Sam Pfanstiel Guest

    Default RE: Having trouble with Time in SQL Server 7.0

    Thanks for the help. I will certainly check out the documents you have referred me to.<BR><BR>Where can I find syntax for more routines such as FormatDateTime()? The book I have (Sams Teach Yourself ASP) has a VBScript primer, but doesn&#039t refer to this (and most likely many other VBScript functions.<BR><BR>Thanks a bunch.<BR><BR>Sam Pfanstiel<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
  •