Sybase date convertion

How do you convert a date 2005-01-20 to a long format as this: Thursday, January 20, 2005

fuseboxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

terabiteauCommented:
DECLARE @ds VARCHAR(30), @dt DATETIME
SELECT @ds = '2005-01-20'
SELECT @ds = SUBSTRING(@ds,6,5) + '-' + SUBSTRING(@ds,1,4)
SELECT @dt = CONVERT(datetime, @ds, 110)
-- Thursday, January 20, 2005
SELECT @ds = CONVERT(VARCHAR, DATENAME(dw, @dt)) + ', ' +
      CASE DATEPART(mm, @dt)
      WHEN 1 THEN 'January'
      WHEN 2 THEN 'February'
      ELSE 'Other'
      END + ' ' +
      CONVERT(VARCHAR, DATEPART(dd, @dt)) + ', ' +
      CONVERT(VARCHAR, DATEPART(yy, @dt))
SELECT @ds

Cheers Frank.
kuldeep_bhayanaCommented:
SELECT CONVERT(char,GETDATE(),107)
Jan FranekCommented:
Your long format is not directly supported by Sybase ASE, so you have to "buid" it yourselves:


datename( weekday, '2005-01-20' ) -> Thursday
datename( month, '2005-01-20' ) -> January
datepart( day, '2005-01-20' ) -> 20
datename( year, '2005-01-20' ) -> 2005

so:

declare @origdate datetime
select @origdate = '2005-01-20'
select datename( weekday, @origdate ) + ', ' + datename( month, @origdate ) + ' ' + convert( varchar(3), datepart( day, @origdate )) + ', ' + convert( varchar(4), datepart( year, @origdate ))

To see formats supported by ASE look at http://sybooks.sybase.com/onlinebooks/group-as/asg1251e/blocks/@ebt-link;pt=11623;lang=cs?target=%25N%15_11838_START_RESTART_N%25

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Sybase Database

From novice to tech pro — start learning today.