Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Convert Months,Days,ShortMonths to different Languages

By William McLaughlin,

This script allows you to convert date languages without exsplicitly setting the language in sql server it can be used in views,storedprocedures and select statements

/**
examples
 posible input values Months,Days,ShortMonths
 Returns all values for the language selected
 select * from dbo.FN_ConvertLanguageValues('Dutch','Months')
 select * from dbo.FN_ConvertLanguageValues('Dutch','Days')
 select * from dbo.FN_ConvertLanguageValues('Dutch','ShortMonths')

'Direct query example returns current month for current date
select item as dutchmonth from dbo.FN_ConvertLanguageValues('Dutch','months') where row = DATEPART(m, getdate())
 
 'Select the dayname for the current day
 select item as dutchday from dbo.FN_ConvertLanguageValues('Dutch','days') where row = DATEPART(weekday, getdate())

 'Table Query Examples
  select myfield,(select item as dutchmonth from dbo.FN_ConvertLanguageValues('Dutch','months') where row = DATEPART(m, mydatefield)) as dutchmonth from mytable
  select myfield,(select item as dutchday from dbo.FN_ConvertLanguageValues('Dutch','days') where row = DATEPART(weekday, mydatefield)) as dutchday from mytable

 Helper Functions

--Example select the day name for the given date

--select dbo.dayNames('Dutch',GetDATE()) as dayname

--Example Select the MonthName for the Given Date

--select dbo.monthNames('Dutch',GetDATE()) as monthname

 -- additional example

Select dbo.daynames('dutch',GetDate()) + ' ' + convert(varchar,Datepart(day,getdate())) + ' ' + dbo.monthnames('dutch',getdate()) + ' ' + convert(varchar(4),year(getdate()))

Total article views: 946 | Views in the last 30 days: 1
 
Related Articles
FORUM

select from GETDATE()?

select from GETDATE()?

FORUM

select 21/(datediff(dd,getdate(),getdate())

select 21/(datediff(dd,getdate(),getdate())

FORUM

GetDate Function

Getdate() as default

FORUM

Issue with trying to incorporate the following SELECT DATEPART(WEEKDAY, GETDATE())

Issue with trying to incorporate the following SELECT DATEPART(WEEKDAY, GETDATE())

FORUM

help using getdate function

help using getdate function

Tags
 
Contribute