|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
What's the function to convert Date to "mmyy" varcharhi
Can anyone help in converting A Date format to text and only display month and year? Thanks Try:
select right (convert (char (6), getdate(), 112), 2) + left (convert (char (6), getdate(), 112), 4) -- Tom ---------------------------------------------------- Thomas A. Moreau, BSc, PhD, MCSE, MCDBA SQL Server MVP Columnist, SQL Server Professional Toronto, ON Canada www.pinpub.com .. "slimla" <sli***@discussions.microsoft.com> wrote in message Can anyone help in converting A Date format to text and only display monthnews:7D110F6A-F934-4C3E-9BFD-B3E84142E8EC@microsoft.com... hi and year? Thanks Thanks Tom
Show quote "Tom Moreau" wrote: > Try: > > select right (convert (char (6), getdate(), 112), 2) + left (convert (char > (6), getdate(), 112), 4) > > -- > Tom > > ---------------------------------------------------- > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA > SQL Server MVP > Columnist, SQL Server Professional > Toronto, ON Canada > www.pinpub.com > .. > "slimla" <sli***@discussions.microsoft.com> wrote in message > news:7D110F6A-F934-4C3E-9BFD-B3E84142E8EC@microsoft.com... > hi > > Can anyone help in converting A Date format to text and only display month > and year? > > Thanks > > Unfortunately The is not native convert style to convert a date to mmyy.
However the following statement should do the job. ie. convert 27/01/2006 to 0106. SELECT SUBSTRING(CONVERT(CHAR(6), GETDATE(), 12), 3, 2) + LEFT(CONVERT(CHAR(6), GETDATE(), 12), 2) If you are regularly having to do this conversion it may be worth while writing a User Defined Function to perform this conversion. HTH - Peter Ward WARDY IT Solutions Show quote "slimla" wrote: > hi > > Can anyone help in converting A Date format to text and only display month > and year? > > Thanks > |
|||||||||||||||||||||||