Ryan Graybeal
September 3rd, 2009, 10:07 AM
I am having a problem with the FormatDate function.
My data is "8/25/09"
return (FormatDate(Field("date***************]"), "ld, lm d, yyyy"))The rule returns "Wednesday 25, 1909" :confused:
Most of us have moved past the 1900's.
What can I do to get the rule to return "Wednesday 25, 2009"
???????????
tobarstep
September 3rd, 2009, 01:36 PM
FormatDate seems to want to use 1900 as default. Fortunately DateFromString seems to be firmly grounded in the 21st century. This worked for me
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.
rpaterick
September 3rd, 2009, 01:50 PM
8/25/2009
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.
Ryan Graybeal
September 3rd, 2009, 02:03 PM
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.
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.
return (FormatDate(Field("date***************]"), "lm d, yyyy"))
Thanks again.
Ryan
rpaterick
September 3rd, 2009, 02:05 PM
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.
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.