views:

13

answers:

2

hi

i have this Ttime as nvarchar(10): "09:52:48" and i have TmpTime as date

and i try to convert like this: "UPDATE MEN SET TmpTime = CONVERT(DATETIME, Ttime ,108 )"

and i get in TmpTime this: "1900-01-01"

why ?

thank's in advance

A: 

You have a column defined as "date" and then you are sending only a time value into it

The date portion defaults to zero which is 01 January 1900 in SQL (in the CONVERT). Then the time is ignored for a date column.

What do you expect to happen?

(The same would happen whether or not you use CONVERT or not because the column is "date")

gbn
i try to convert text to datei need to get in the date field the value of text field
Gold
Your text is a time. Not a date. What date to you want? Today?if you want date, ask for date. I explianed why you get 01 jan 1900 **which is what you asked for**
gbn
+1  A: 

If you also have a date field, you should to concatenate them before to cast:

CREATE TABLE #Sample ( DateField varchar(10), TimeField varchar(10) );
GO

INSERT INTO  #Sample VALUES ('2009-01-24', '09:52:48');
SELECT CONVERT(DATETIME, DateField + ' ' + TimeField) as Converted FROM #Sample

And you'll get:

Converted
-----------------------
2009-01-24 09:52:48.000
Rubens Farias
oK,and how to show 2010-01-21 00:00:00.000 as 21/01/2010and 1900-01-01 09:09:18.000 as 09:09:18
Gold
Gold, they're two different things; do you have that datefield?
Rubens Farias