apalmer Posted May 25, 2011 Share Posted May 25, 2011 (edited) I've been formatting the dates in my pieces successfully using: var MyDate = Field("Date1"); return FormatDate(MyDate, "ld, lm d, yyyy"); Is there a way to have the ld, lm, d, yyyy show up in a Spanish format? I see that the correct way to format a date in Spanish is (ld d de lm de yyyy) like so: martes 12 de octubre de 2011. Angie Edited May 25, 2011 by apalmer it was cut off. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted May 25, 2011 Share Posted May 25, 2011 Try this: function SpanishDate(myDate) { var months = ['enero','febrero','marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','diciembre']; var days = ['domingo','lunes','martes','miércoles','jueves','viernes','sábado']; var month = months[myDate.getMonth()]; var day = days[myDate.getDay()]; return day + " " + myDate.getDate() + " de " + month + " de " + myDate.getFullYear(); } return SpanishDate(Today()); Quote Link to comment Share on other sites More sharing options...
apalmer Posted May 26, 2011 Author Share Posted May 26, 2011 That worked great. But I need to tweak it so that it's whatever date the user enters into the field, not just today's date. I have a couple of fields that will be filled out and want all of them to have the Spanish format. Field("Date1") Field("Date2") Field("Date3") Field("Date4") Any ideas? Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted May 26, 2011 Share Posted May 26, 2011 That worked great. But I need to tweak it so that it's whatever date the user enters into the field, not just today's date. I have a couple of fields that will be filled out and want all of them to have the Spanish format. Field("Date1") Field("Date2") Field("Date3") Field("Date4") Any ideas? Sure, just call the function with whatever date you want, like so: return SpanishDate(DateFromString(Field("Date1"))); You can put the SpanishDate function in your JavaScript Globals if you need to access it from multiple rules. Quote Link to comment Share on other sites More sharing options...
mdlivels Posted August 3, 2015 Share Posted August 3, 2015 This is wonderful, thanks - Is there a way that I can make this rule dependent upon the "language" field? So if "English" return today's date in English. If "Spanish" return today's date in Spanish. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
step Posted August 3, 2015 Share Posted August 3, 2015 This will return the Spanish date if the language is set to "Spanish," for anything else it will return English: function SpanishDate(myDate) { var months = ['enero','febrero','marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','diciembre']; var days = ['domingo','lunes','martes','miércoles','jueves','viernes','sábado']; var month = months[myDate.getMonth()]; var day = days[myDate.getDay()]; return day + " " + myDate.getDate() + " de " + month + " de " + myDate.getFullYear(); } return (FusionPro.language == "Spanish") ? SpanishDate(Today()) : FormatDate(Today(), 'lm d, yyyy'); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 3, 2015 Share Posted August 3, 2015 This will return the Spanish date if the language is set to "Spanish," for anything else it will return English: Yes, it will, although I think the question was about the value from a data field named "language", rather than about the language under which FusionPro's UI is running: Is there a way that I can make this rule dependent upon the "language" field? So the last line would be this instead: return (Field("language") == "Spanish") ? SpanishDate(Today()) : FormatDate(Today(), 'lm d, yyyy'); However, in FusionPro 9.2 or later, the day and month names are already translated into Spanish, as well as German, French, Italian, Japanese, and Chinese (both traditional and simplified), so you don't need to provide your own translations. You just need to specify the language as the (optional) third parameter to FormatDate, like so: return FormatDate(Today(), "EE, lm d, yyyy", "Spanish"); Just that one liner is all you need. Or specify any of those other languages. This should work for mdlivels: return FormatDate(Today(), "EE, lm d, yyyy", Field("language")); Or, if you want to do that based on FusionPro's installed language: return FormatDate(Today(), "EE, lm d, yyyy", FusionPro.language); Quote Link to comment Share on other sites More sharing options...
mdlivels Posted August 3, 2015 Share Posted August 3, 2015 Thanks - that worked beautifully! Quote Link to comment Share on other sites More sharing options...
msteinberger Posted January 3, 2020 Share Posted January 3, 2020 Is there a way to use this same formula but also pull in a date field from the data instead of using Today's Date? Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted January 3, 2020 Share Posted January 3, 2020 Is there a way to use this same formula but also pull in a date field from the data instead of using Today's Date? Sure, something like: return FormatDate(DateFromString(Field("Birthday")), "EE, lm d, yyyy", "Spanish"); Be aware that the DateFromString function makes certain assumptions about the format of the string it's parsing, such as favoring US-style mm/dd/yyyy over European-style dd/mm/yyyy, for one. Quote Link to comment Share on other sites More sharing options...
msteinberger Posted January 6, 2020 Share Posted January 6, 2020 Thank you! I ended up with this as my final rule. It displays the date in English or Spanish based on a language column in the data as well as a predetermined date that is also in the data: function SpanishDate(myDate) { var months = ['enero','febrero','marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','diciembre']; var letterdate = Field("letter date") var month = months[myDate.getMonth()]; return myDate.getDate() + " de " + month + " " + myDate.getFullYear(); } return (Field("language") == "S") ? SpanishDate(DateFromString(Field("letter date"))) : FormatDate(DateFromString(Field("letter date")), 'lm d, yyyy'); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.