Convert NVARCHAR to DATETIME in SQL Server 2008

前端 未结 6 685
刺人心
刺人心 2020-12-18 06:18

In my table

LoginDate  
2013-08-29 13:55:48  

The loginDate column\'s datatype is nvarchar(150)

I want

6条回答
  •  无人及你
    2020-12-18 07:01

    What you exactly wan't to do ?. To change Datatype of column you can simple use alter command as

    ALTER TABLE table_name ALTER COLUMN LoginDate DateTime;

    But remember there should valid Date only in this column however data-type is nvarchar.

    If you wan't to convert data type while fetching data then you can use CONVERT function as,

    CONVERT(data_type(length),expression,style)

    eg:

    SELECT CONVERT(DateTime, loginDate, 6)

    This will return 29 AUG 13. For details about CONVERT function you can visit ,

    http://www.w3schools.com/sql/func_convert.asp.

    Remember, Always use DataTime data type for DateTime column.

    Thank You

提交回复
热议问题