SQLTeam.com | Weblogs | Forums

Converting date


#1

HI
I have a date in sql dB as 1998-12-14

I want to convert it to below and I am using below code but getting error, can you help?

Where EFFDT >= CONVERT(varchar, Convert(datetime,'14-12-1998 00:00:00'),101)


#2

What datatype is EFFDT? (please post create statement)


#3

EFFDT is a date:

SELECT TOP (10) EFFDT
FROM dbo.[EMPL_HIST
Where EFFDT >= CONVERT(varchar, Convert(datetime,'14-12-1998 00:00:00'),101)

Hope this helps.
Thanks,


#4

Then you can use:

Query
select top(10)
       effdt
  from dbo.ps_dm_empl_hist_vw
 where effdt>=cast('1998-12-14' as date)

#5

Thanks but this is what I get still the same: its not Converted? I want it like this--> 14-12-1998 dd-mm-yyyy
1998-12-14
1998-12-19
2003-03-17


#6
select top(10)
       convert(varchar,effdt,105)
  from dbo.ps_dm_empl_hist_vw
 where effdt>=cast('1998-12-14' as date)

#7

Thanks It works I had to do set it up in select .
Thanks so much!


#8

Watch out for the default size when when using VARCHAR. Better to specify the size you want, rather than to get in the habit of using the default and then getting caught out.


#9

@bitsmed, what did you do to get the Query drop-down message in your post?


#10

Press option (next to the smiley) and choose hide details or do this:
[ details="Query"]
Blah blah blah
[/details]


#11
Well
I
Never
Knew
That!

:slight_smile:


#12

Thanks for tips!