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 September 3rd, 2009, 10:07 AM
Ryan Graybeal's Avatar
Ryan Graybeal Ryan Graybeal is offline
Junior Community Member
 
Join Date: Sep 2008
Location: Seattle Washington
Posts: 38
Default format date function problem

I am having a problem with the FormatDate function.

My data is "8/25/09"


Code:
return (FormatDate(Field("date***************]"), "ld, lm d, yyyy"))
The rule returns "Wednesday 25, 1909"

Most of us have moved past the 1900's.

What can I do to get the rule to return "Wednesday 25, 2009"
???????????
__________________
Ryan Graybeal
ColorGraphics

A Cenveo Company

FP 9.3.6 Mac OS X 10.7.5
Acrobat 10
ryan.graybeal@cenveo.com
Reply With Quote
  #2  
Old September 3rd, 2009, 01:36 PM
tobarstep tobarstep is offline
Regular Contributor
 
Join Date: Sep 2008
Location: Florida
Posts: 71
Default Re: format date function problem

FormatDate seems to want to use 1900 as default. Fortunately DateFromString seems to be firmly grounded in the 21st century. This worked for me
Code:
return FormatDate(DateFromString("8/25/09"), "ld, lm d, yyyy");
Obviously replace the date literal with your field.

I would suggest looking into getting the data formatted with 4 digit years if possible. From a programming standpoint it's the way to go.
__________________
FusionPro VDP 9.3.12 Desktop/Server
Windows 7 Enterprise / Windows Server 2008 r2
Acrobat X
Reply With Quote
  #3  
Old September 3rd, 2009, 01:50 PM
rpaterick rpaterick is offline
Senior Contributor
 
Join Date: Mar 2009
Posts: 427
Default Re: format date function problem

8/25/2009

Code:
return FormatDate(Field("date"), "ld, lm d, yyyy");
would look like: Tuesday, August 25, 2009

This will pull your date from the data and format it for different dates that you may have throughout the run. You could modify it to just read Tuesday, 25, 2009 if you wanted to.
__________________
Windows 7 64BIT
Intel - I7 chip - 3.33Ghz - 6GB ram
8.0 Creator/8.0 Producer/CS5.5

Last edited by rpaterick; September 3rd, 2009 at 02:03 PM..
Reply With Quote
  #4  
Old September 3rd, 2009, 02:03 PM
Ryan Graybeal's Avatar
Ryan Graybeal Ryan Graybeal is offline
Junior Community Member
 
Join Date: Sep 2008
Location: Seattle Washington
Posts: 38
Default Re: format date function problem

Thanks for all of you help.

I did find a solution. Here is what I did.

I went in and found the Builtins.js file ---
(mac) library/application support/Printable/FusionPro

I opened it in a text editor and found the function for FormatDate

I then copied the function into my FP rule.

Code:
function FormatDate(date_, format, lang)
{
    var _lang = ToTitleCase(Trim("" + (lang || "English"))); // FusionPro.language
    if (typeof MONTH_NAMES[_lang] == "undefined")
    {
      var names = "";
      for (var i in MONTH_NAMES)
        names += (names ? ", " : "") + '"' + i + '"';
      ThrowError("FormatDate", TranslateAndBuildMessage("Invalid language: \"{0}\".  Must be one of: {1}.", lang, names));
    }

 try {    
    format = ReplaceSubstring(format,"sd","E")
    format = ReplaceSubstring(format,"ld","EE")
    format = ReplaceSubstring(format,"sm","NNN")
    format = ReplaceSubstring(format,"lm","MMM")
    //format = ReplaceSubstring(format,"mm","MM")
    format = ReplaceSubstring(format,"m","M")

    format=format+"";
    var result="";
    var i_format=0;
    var c="";
    var token="";
  var date = new Date(date_);
    var y=date.getYear()+"";
    var M=date.getMonth()+1;
    var d=date.getDate();
    var E=date.getDay();
    var H=date.getHours();
    var m=date.getMinutes();
    var s=date.getSeconds();
    var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
    // Convert real date parts into formatted versions
    var value=new Object();
    if (y.length < 4) {y=""+(y-0+1900);} // I change this to 2000
    value["y"]=""+y;
    value["yyyy"]=y;
    value["yy"]=y.substring(2,4);
    value["M"]=M;
    value["MM"]=LZ(M);
    value["MMM"]=MONTH_NAMES[_lang][M-1];
    value["NNN"]=Left(MONTH_NAMES[_lang][M-1], 3);
    value["d"]=d;
    value["dd"]=LZ(d);
    value["E"]=Left(DAY_NAMES[_lang][E], 3);
    value["EE"]=DAY_NAMES[_lang][E];
    value["H"]=H;
    value["HH"]=LZ(H);
    if (H==0){value["h"]=12;}
    else if (H>12){value["h"]=H-12;}
    else {value["h"]=H;}
    value["hh"]=LZ(value["h"]);
    if (H>11){value["K"]=H-12;} else {value["K"]=H;}
    value["k"]=H+1;
    value["KK"]=LZ(value["K"]);
    value["kk"]=LZ(value["k"]);
    value["a"]= (H > 11) ? "pm" : "am";
  value["A"] = ToUpper(value["a"]);
    value["m"]=m;
    value["mm"]=LZ(m);
    value["n"]=m;
    value["nn"]=LZ(m);
    value["s"]=s;
    value["ss"]=LZ(s);
    while (i_format < format.length) {
        c=format.charAt(i_format);
        token="";
        while ((format.charAt(i_format)==c) && (i_format < format.length)) {
            token += format.charAt(i_format++);
            }
        if (value[token] != null)         
        { result=result + value[token]; }
        else { result=result + token; }
        }
    return result;
 }
 catch (e)
 {
    ThrowError("FormatDate", "The input string is invalid.");
    //return inputString;
 }
}// end function formatDate(date,format)

//__________________________________________________________________
FormatDate.builtin = true;
I had to ad one piece of code at the bottom of the rule to get the function to work.

Code:
return (FormatDate(Field("date***************]"), "lm d, yyyy"))
Thanks again.

Ryan
__________________
Ryan Graybeal
ColorGraphics

A Cenveo Company

FP 9.3.6 Mac OS X 10.7.5
Acrobat 10
ryan.graybeal@cenveo.com
Reply With Quote
  #5  
Old September 3rd, 2009, 02:05 PM
rpaterick rpaterick is offline
Senior Contributor
 
Join Date: Mar 2009
Posts: 427
Default Re: format date function problem

Quote:
Originally Posted by Ryan Graybeal View Post
Thanks for all of you help.

I did find a solution. Here is what I did.

Thanks again.

Ryan
I modified my post a little more clearer.
__________________
Windows 7 64BIT
Intel - I7 chip - 3.33Ghz - 6GB ram
8.0 Creator/8.0 Producer/CS5.5
Reply With Quote
  #6  
Old March 29th, 2010, 02:47 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: format date function problem

Code:
return FormatDate(Field("date"), "ld, lm d, 20yy");
Reply With Quote
Reply

Tags
date, format date

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 01:32 AM.


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