Printing Partners Posted August 26, 2016 Share Posted August 26, 2016 Okay, I have been looking at this too long and it isn't making sense anymore. Below is my code, it breaks down where I try to assign the new value. I am re-formatting a date submitted via a spreadsheet. so their date of "10-Aug-16" or "16 August 2016" or "16-August-2016" returns as "16 August 2016". if (Field("InductionDate") != "") { var str = Field("InductionDate"); var arr = str.split(/[- ]+/); var day = arr[0]; var month = arr[1]; var year = arr[2]; if (month.length < 4) { var editmonth = month.replace(/Aug/g,"August") .replace(/Sept/g,"September"); } else { editmonth = month; } if (year.length == 4) { var edityear = year; } else { edityear = "20" + year; } var Field("InductionDate") = day + " " + editmonth + " " + edityear; return (Field("InductionDate"); } else { return "error"; } My script functions in a normal javascrip environment, but assigning the new value to the FusionPro Field "InductionDate" is where i am failing. I know it is something simple, I just can't see it. Quote Link to comment Share on other sites More sharing options...
Printing Partners Posted August 26, 2016 Author Share Posted August 26, 2016 Figured it out. I was over thinking my code. if (Field("InductionDate") != "") { var str = Field("InductionDate"); var arr = str.split(/[- ]+/); var day = arr[0]; var month = arr[1]; var year = arr[2]; if (month.length <= 4) { var editmonth = month.replace(/Jan/g,"January") .replace(/Feb/g,"February") .replace(/Mar/g,"March") .replace(/Apr/g,"April") .replace(/May/g,"May") .replace(/Jun/g,"June") .replace(/Jul/g,"July") .replace(/Julyy/g,"July") .replace(/Aug/g,"August") .replace(/Sept/g,"September") .replace(/Oct/g,"October") .replace(/Nov/g,"November") .replace(/Dec/g,"December"); } else { editmonth = month; } if (year.length == 4) { var edityear = year; } else { edityear = "20" + year; } return day + " " + editmonth + " " + edityear; } else { return "error"; } Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 26, 2016 Share Posted August 26, 2016 (edited) This should work as well: var str = Field("InductionDate"); var [day, month, year] = str.split(/[-\/ ]+/); if ([day,year].map(isNaN).some(Boolean)) return "error"; var Left3Lower = function(s){return(ToLower(Left(s,3)));}; month = Int(month) || MONTH_NAMES.English.map(Left3Lower).indexOf(Left3Lower(month)) + 1; if (day < 1 || day > 31 || month < 1 || month > 12) return "error"; return FormatDate(DateFromString([month,day,year].join("/")), "dd lm yyyy"); Edited August 26, 2016 by Dan Korn Added error checking for month and day. Quote Link to comment Share on other sites More sharing options...
step Posted August 26, 2016 Share Posted August 26, 2016 As would this assuming you're okay with formatting every year as 20##: var date = Field("InductionDate").replace(/[-\s]|(\d+)$/g, function(s,p) {return p ? '20' + p.slice(-2) : ' ' }); return FormatDate(new Date(date), 'd lm 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.