UK date in text field as a true date

  • I have a date held in a varchar field in a temporary sql table and I want to convert it into a sql date and it doesn't work. I can replicate this as below -

    So I run

    select

    cast ('14/02/2014' as date)

    and I get a conversion failed error. what am I doing wrong ?

  • you'll wnat to set your session variable for dateformat to handle this for you:

    SET DATEFORMAT DMY

    select

    cast ('14/02/2014' as date)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • or use convert() with style 103

    select convert(date, '14/02/2014', 103)

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

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