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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 date display format

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2007-01-11 : 02:27:21
dob='2006-05-15'
need to display in format given below
may-2006

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-11 : 02:32:40
Once again we turn to Books Online, an excellent source of information, and find this solution
declare @dob datetime
select @dob = '20060515'

select datename(month, @dob) + '-' + datename(year, @dob)

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

sshelper
Posting Yak Master

216 Posts

Posted - 2007-01-11 : 10:57:15
If you just want the first 3 characters of the month, simply do a LEFT substring to what Peter has provided:

declare @dob datetime
select @dob = '20060515'

select LEFT(datename(month, @dob), 3) + '-' + datename(year, @dob)

For other date formats, you may also refer to the following link:

http://www.sql-server-helper.com/tips/date-formats.aspx

SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-11 : 15:05:59
Or

select right(convert(varchar, getdate(), 106), 8)

Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -