Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display months in welsh 1

Status
Not open for further replies.

NickyJay

Programmer
Sep 1, 2003
217
GB
Hi Guys,

i have a site that allows users to edit educational leaflets, both in english and welsh. I am stuck, however, on getting the date the leaflet was last updated (displayed as "Month, Year") to output using the welsh translation of month names.

My table holds the information as a Date/Time value. The field is automatically completed when a leaflet is changed. I have used #DATEFORMAT(DateUpdated, "mmmm yyyy")# to output just month and year from this field.

Should i be looking at cfcase for this? how do i get it to just pick the month?

any help is appreciated!
Thanks [ponder]
 
here's one way to do it

set up a string of month names, using the same max length for each (for example, in english and german, september is the longest month name, so make all of the month names the same length)

'Januar Februar März April Mai Juni Juli August SeptemberOktober November Dezember'

then you can pull out the month name using simple substring arithmetic based on the month number

select substring('Januar Februar März April Mai Juni Juli August SeptemberOktober November Dezember',month(DateUpdated)*9-8,9) as themonth
, year(DateUpdated) as theyear
from ...

r937.com | rudy.ca
 
Oh how I wish there was a function in CF that output welsh month names!

What you are going to need to do is to write your own function to do this. You'll have to do something like this:

Code:
  <cffunction name="WelshMonth" returntype="string">
    <cfargument name="EnglishMonth" type="numeric">

    <cfswitch expression="#Arguments.EnglishMonth#">
      <cfcase value="1">
        <cfreturn "Ionawr">
      </cfcase>
      <cfcase value="2">
        <cfreturn "Chwefror">
      </cfcase>
      .
      .
    </cfswitch>
  </cffunction>
  
  <cfoutput>
    #WelshMonth(Month(DateUpdated))#
  </cfoutput>

and then combine this with the date formatting options within cf, like:

Code:
#DateFormat(DateUpdated, 'dd')# #WelshMonth(Month(DateUpdated))# #DateFormat(DateUpdated, 'yyyy')#

You could just use the day and year functions here if you wanted

Hope this helps!

Tony
 
Hi Guys thanks for responding :)

I'll give both a go and see how i get on, r937, you seem to come to my assistance a lot, Thank You!!

Nicola
 
if you use a function, you can make it shorter and simpler than using CFSWITCH/CASE, while adding even more flexibility (long month names & short month names)

(i don't know welsh....)

Code:
<cffunction name="WelshMonth" returntype="string">
    <cfargument name="EnglishMonth" type="numeric">
		<cfargument name="mode" type="string" required="No" default="long">
		
		<cfset var thisMonth = "">
		<cfset var monthNames = "">
		<cfset var longMonthNames = "Ionawr,Chwefror,March,April,May,June,July,August,September,October,November,December">
		<cfset var shortMonthNames = "Ion,Chwe,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec">
		
		<cfif arguments.mode EQ "long">
			<cfset monthNames = longMonthNames>
		<cfelse>
			<cfset monthNames = shortMonthNames>
		</cfif>
		
   	<cfif Arguments.EnglishMonth GT 12 OR NOT Arguments.EnglishMonth>
			<cfset thisMonth = "Invalid Month">
		<cfelse>	
			<cfset thisMonth = listGetAt(monthNames,Arguments.EnglishMonth)>
		</cfif>
		
	 	
		<cfreturn thisMonth />
  </cffunction>
  
  <cfoutput>
    #WelshMonth(0,"short")#
  </cfoutput>

Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top