Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

CAST Date to Character Expand / Collapse
Author
Message
Posted Wednesday, October 16, 2013 3:39 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 3:18 AM
Points: 177, Visits: 418
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.
Post #1505123
Posted Wednesday, October 16, 2013 3:43 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 9:09 AM
Points: 3,088, Visits: 3,329
Try this :-
convert(CHAR(10), getdate() ,120)

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


-------------------------------
Posting Data Etiquette - Jeff Moden
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
Post #1505124
Posted Wednesday, October 16, 2013 4:05 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 3:18 AM
Points: 177, Visits: 418
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.
Post #1505130
Posted Wednesday, October 16, 2013 1:53 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 9:09 AM
Points: 3,088, Visits: 3,329
You're welcome - I try to keep everything simple - it makes life easier for the next guy!

-------------------------------
Posting Data Etiquette - Jeff Moden
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
Post #1505406
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse