Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Formatting Text

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 25th, 2011, 09:21 AM
apalmer's Avatar
apalmer apalmer is offline
Forum n00b
 
Join Date: Apr 2011
Location: New Orleans, LA
Posts: 7
Default Format Date in Spanish

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

Last edited by apalmer; May 25th, 2011 at 09:25 AM.. Reason: it was cut off.
Reply With Quote
  #2  
Old May 25th, 2011, 01:51 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,359
Default Re: Format Date in Spanish

Try this:
Code:
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());
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #3  
Old May 26th, 2011, 08:10 AM
apalmer's Avatar
apalmer apalmer is offline
Forum n00b
 
Join Date: Apr 2011
Location: New Orleans, LA
Posts: 7
Default Re: Format Date in Spanish

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?
Reply With Quote
  #4  
Old May 26th, 2011, 01:52 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,359
Default Re: Format Date in Spanish

Quote:
Originally Posted by apalmer View Post
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:
Code:
return SpanishDate(DateFromString(Field("Date1")));
You can put the SpanishDate function in your JavaScript Globals if you need to access it from multiple rules.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #5  
Old August 3rd, 2015, 02:06 PM
mdlivels mdlivels is offline
Junior Community Member
 
Join Date: May 2011
Location: Gettysburg, PA
Posts: 17
Default Re: Format Date in Spanish

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.
Reply With Quote
  #6  
Old August 3rd, 2015, 02:57 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Format Date in Spanish

This will return the Spanish date if the language is set to "Spanish," for anything else it will return English:
Code:
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');
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #7  
Old August 3rd, 2015, 04:12 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,359
Default Re: Format Date in Spanish

Quote:
Originally Posted by step View Post
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:
Quote:
Originally Posted by mdlivels View Post
Is there a way that I can make this rule dependent upon the "language" field?
So the last line would be this instead:
Code:
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:
Code:
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:
Code:
return FormatDate(Today(), "EE, lm d, yyyy", Field("language"));
Or, if you want to do that based on FusionPro's installed language:
Code:
return FormatDate(Today(), "EE, lm d, yyyy", FusionPro.language);
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #8  
Old August 3rd, 2015, 04:30 PM
mdlivels mdlivels is offline
Junior Community Member
 
Join Date: May 2011
Location: Gettysburg, PA
Posts: 17
Default Re: Format Date in Spanish

Thanks - that worked beautifully!
Reply With Quote
Reply

Tags
date, format, spanish

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:59 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.