Convert NVARCHAR columns to DATETIME

  • Hi All,

    I have a table which contains a number of columns all set as NVARCHAR(50).

    One column in particular i want to query is a column called "Date" (lol)

    Example date in column "Date" :

    08/11/1999

    26/11/1999

    26/11/1999

    Unfortunately the column is set to NVARCHAR(50) so I cannot do:

    Select *

    FROM Client

    WHERE date >= '08/11/1999'

    I have tried things like:

    select cast('bgn date' as datetime)

    from dbo.Client

    Does not work

    How can I resolve this?

  • CONVERT( datetime, [Date], 103 )

  • OK, thanks.

    I used the following:

    SELECT CONVERT( datetime, [bgn date], 103 ) as date

    from date

    Two things

    1. I want to select the rest of the columns in the table too.

    2. I need to add a where clause where date >= 08/11/1999

  • Prehaps this will help

    CREATE TABLE #Client(ClientID INT,[bgn Date] VARCHAR(50))

    INSERT INTO #Client

    SELECT 1,'08/11/1999' UNION ALL

    SELECT 2, '26/11/1999' UNION ALL

    SELECT 3, '26/11/1999'

    SELECT Clientid,CONVERT( datetime, [bgn date], 103 ) as date from #Client

    WHERE CONVERT( datetime, [bgn date], 103 ) > CONVERT( datetime, '08/11/1999', 103 )

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply