Convert string -> date | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Convert string -> date

Hi, help me please..
I need convert string ‘10.04.2004’ to date 10.04.2004 by update. Could you write me correct statement ?
Thanks, Lubo

What is the DataType of the Column you want to update? Madhivanan Failing to plan is Planning to fail
you can use cast or convert —————————————-
Cast your vote
http://www.geocities.com/dineshasanka/sqlserver05.html http://spaces.msn.com/members/dineshasanka

Check out CAST or CONVERT. And in case you want some additional checking, have a look at ISDATE() in BOL. —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Ich unterstütze PASS Deutschland e.V. http://www.sqlpass.de)

I want convert column Datum , varchar(255). After that to write converted value to write to
column dateKonv ( datetime ). I want upddate this column in procedure
Value datum = ‘10.04.2004’ ; or if it isn’t possible ‘10.04.04’
converted value = 10.04.2004 or 10.04.2004
Try this Update yourTable set dateKonv =Cast(Datum as DateTime) Madhivanan Failing to plan is Planning to fail
ok, but i don’want format
2005-04-10 00:00:00.000 I want only 04.10.2005

Thats not the problem
You should handle that in your Presentation layer Otherwise in your Select Statement use this Select Convert(varchar,DateKonv,104) from yourTable Madhivanan Failing to plan is Planning to fail
There is no such thing as a date format in SQL Server. Internally it stores something completely different. See if this helps:http://www.sql-server-performance.com/fk_datetime.asp
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Ich unterstütze PASS Deutschland e.V. http://www.sqlpass.de)

Frank, I forget to show your link [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br /><br />Madhivanan<br /><br />Failing to plan is Planning to fail
Problem… When I always make your example result is 2005-04-10 00:00:00.000 My statement for Update with convert is
Update Detail set detail.datKOnv=convert(varchar,Datum,104)

oh my god, it’s true . Value in table is 10.04.2004
And to top this, what you see isn’t what is stored. <br />Try SELECT CAST(‘20040410′ AS BINARY(<img src=’/community/emoticons/emotion-11.gif’ alt=’8)’ />) to see how SQL Server internally stores DATETIME values. Here’s another good link on that matter:<a target="_blank" href=http://www.karaszi.com/sqlserver/info_datetime.asp>http://www.karaszi.com/sqlserver/info_datetime.asp</a><br /><br />–<br />Frank Kalis<br />Microsoft SQL Server MVP<br /<a target="_blank" href=http://www.insidesql.de>http://www.insidesql.de</a><br />Ich unterstütze PASS Deutschland e.V. <a target="_blank" href=http://www.sqlpass.de>http://www.sqlpass.de</a>) <br />
Luma, why do you worry on how date is stored in a table?
It is your Presentation layer that convert it to the format you want Madhivanan Failing to plan is Planning to fail
]]>