Friday, February 17, 2012

Data Type (Time Format)

Hi all,
I have a colume assigned to datetime format, where the value is say
"06:31:31" rather than 20/05/2004 06:31:31. When I retrieve the value from
the table, the result were 30/12/1899 06:31:31. Is there a way to change the
format so that I only need to put the time variable into the field as
opposed to the full datetime format?
Thanks
There is no datatype in SQL Server for just time. However, display is a
client issue; you should be able to pull just the time element out in
whatever language you're using for reporting/application development. You
can also use CONVERT to pull the time out as a text string:
SELECT CONVERT(CHAR(8), YourDateTimeCol, 8) AS TheTime
FROM YourTable
If, as I suspect, what you're storing is actually a duration, you might
consider storing it as number of seconds in a column of integer datatype
instead of using datetime. This will make calculations (if necessary) much
easier.
"VampireJ" <jwlchung@.yahoo.com.hk> wrote in message
news:ujXbOHmPEHA.556@.tk2msftngp13.phx.gbl...
> Hi all,
> I have a colume assigned to datetime format, where the value is say
> "06:31:31" rather than 20/05/2004 06:31:31. When I retrieve the value from
> the table, the result were 30/12/1899 06:31:31. Is there a way to change
the
> format so that I only need to put the time variable into the field as
> opposed to the full datetime format?
> Thanks
>
|||Thanks very much, I will give that a try.
"Adam Machanic" <amachanic@.air-worldwide.nospamallowed.com> wrote in message
news:e1WsrfoPEHA.2580@.TK2MSFTNGP09.phx.gbl...
> There is no datatype in SQL Server for just time. However, display is a
> client issue; you should be able to pull just the time element out in
> whatever language you're using for reporting/application development. You
> can also use CONVERT to pull the time out as a text string:
> SELECT CONVERT(CHAR(8), YourDateTimeCol, 8) AS TheTime
> FROM YourTable
> If, as I suspect, what you're storing is actually a duration, you might
> consider storing it as number of seconds in a column of integer datatype
> instead of using datetime. This will make calculations (if necessary)
much[vbcol=seagreen]
> easier.
>
> "VampireJ" <jwlchung@.yahoo.com.hk> wrote in message
> news:ujXbOHmPEHA.556@.tk2msftngp13.phx.gbl...
from
> the
>
|||hi
i have the same problem that you have.
can you please let me know if you find the solution.
thanks
alina
************************************************** ********************
Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...

No comments:

Post a Comment