Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 date format

Author  Topic 

psangeetha
Yak Posting Veteran

95 Posts

Posted - 2009-08-20 : 10:51:44
Hi all,

In oracle I use this query to format the date field. chg_dt is a date field in addchg table

select to_char(chg_dt,'YYYY/DD/MM HH:MI') as date from addchg;

DATECHG
----------------
2002/11/11 12:00

How can I do this in sql server?? Seems to be too complicated... I tried using convert but couldnt get this format

select convert(datetime, chg_dt,112) from addchg

I keep getting 2002-11-11 12:00:00:000

Please help thanks

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-08-20 : 11:03:50
There could be a better way...but I think this?

select convert(varchar(12),getdate(),111) + ' ' + convert(varchar(5),getdate(),108)
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-08-21 : 00:29:06
see this links for formattion of dates
http://www.sql-server-helper.com/tips/date-formats.aspx
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=80563

if it is presentation issue u can do it in front end.....
Go to Top of Page
   

- Advertisement -