MSSQL Server:conversion of char or varchar to datetime type
Hi
I have a problem while converting the char to datetime type in MSSQL Server 200/2005.
I want to retrieve the date values from table in datetime data type in a particular format like 'yyyydd' or 'yyyy/dd' similar to oracle's TO_DATE function.
For this I tried with following query,
SELECT CONVERT(datetime, CONVERT(varchar(6), date1, 112), 112) from sql_dm1
But I got the following error while executing the above query:
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
Please help me in this regard.
Thanks
Sridhar
Its not possible with datetime type
The datetime type by default needs all the three parts. The alternative could be you get the data in whatever format SQL gives you, then in the front-end you can convert and sort it the way you need
Convert row from varchar to datetime
Hy,
I have a few table and one of the row is date but in in varchar format.(now the format is mm/dd/yyyy).
Now i want to convert the row in datetime format mssql but like this(dd.mm.yyyy)
I can change this?