CAST Date to Character

  • Hi,

    I have a field that is DATE format -

    contains either "NULL" which shows as "1900-01-01 00:00:00.000"

    or valid dates of "2013-10-16 00:00:00.000"

    I would like to cast this as a char so that I get " " or "2013-10-16"

    I have tried to

    CAST ( tableFieldDate as varchar(30) )

    but get "Jan 1 1900 12:00AM"

    should I be CAST and then embedding a date format ?

    Thanks in advance

    ________________________________________________________________________________________________
    Regards
    Steve
    SQL 2008 DBA/DBD - MCTS/MCITP

    Please don't trust me, test the solutions I give you before using them.

  • Try this :-

    convert(CHAR(10), getdate() ,120)

    I think it might suit what you're trying to do

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

  • Brilliant - thank you.

    I do like Simple answers

    ________________________________________________________________________________________________
    Regards
    Steve
    SQL 2008 DBA/DBD - MCTS/MCITP

    Please don't trust me, test the solutions I give you before using them.

  • You're welcome - I try to keep everything simple - it makes life easier for the next guy!

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

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

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