PDA

View Full Version : Formatting Dates


keangirl
March 29th, 2010, 12:08 PM
I'm a new user and would like to make sure that dates on a certain document are displayed as follows: January 3, 2010. I don't want 01/03/10 or any version of that kind of date display.

What would be the best way to go about this? I'm not sure and this is my first document.

Any advice?

esmith
March 29th, 2010, 12:53 PM
It would be easy enough to create a JS rule that would convert data from the mm/dd/yy format to a "longhand" format, but not as easy if data is received in a different format from record to record.

Will all data be received in the mm/dd/yy format?
As opposed to the following scenario:
R1 - 01/03/10
R2 - January 3, 2010
R3 - January 3rd 2010
R4 - Jan 3, 2010
R5 - 1.3.10
etc...

keangirl
March 29th, 2010, 12:56 PM
I'm wondering if I should not allow the users to input a date but rather select from a calendar and have that date popluate into the document in the specific format I'm wanting. It seems easier to control the input that way but I'm not exactly sure how to go about that. Its been too long since my training at Printable and there are huge gaps in my notes. I've looked through the online users guide and the one I got in class but can't find what I'm looking for.

esmith
March 29th, 2010, 01:07 PM
Are you using MarcomCentral? If so, I would repost this question in that forum since I don't use that specific product.

I would think that you would have the ability when setting up the input fields to require information to be entered in a specific format (i.e. mm/dd/yy validates, but Jan 3, 2010 does not and possibly returns an error message).

Dan Korn
March 29th, 2010, 02:47 PM
I'm a new user and would like to make sure that dates on a certain document are displayed as follows: January 3, 2010.
Something like this:
return FormatDate(Field("YourFieldName", "lm d, yyyy"));Once you have a valid Date object, the FormatDate function can be used to output into almost any format you desire. Please refer to the FusionPro Rules System Guide for more information.

As Eric alluded to, the format of the input data field may be significant, but the DateFromString and FormatDate functions should handle most common cases. Although it's always best to avoid any possible ambiguity issues: the most common ones are the good old Y2K bug with two-digit year specifications, and confusion between day and month numbers (e.g. "10/3" is generally understood as October 3rd in the U.S., but as March 10th in the U.K.).

Exactly how you would get the input data into a specific format from a user web form is beyond the scope of this forum. As Eric said, if you're asking about MarcomCentral, please post in that forum (http://forums.printable.com/forumdisplay.php?f=15).

JCrocker
June 8th, 2011, 12:14 PM
Hey Dan, I am having some trouble formatting some dates. I found this thread and FP seems to think it is ok but is returning the incorrect information. For example:

Using this code:

return FormatDate(Field("Field13", "lm d, yyyy"));

Field13 being 5/17/2011 FP returns u017efi0e17

Im actually just trying to get it to return the month and day which i believe would be:

return FormatDate(Field("Field13", "mm/dd"));

Field13 being 5/17/2011 it still returns u017efi0e17 the same thing

Any Ideas or suggestions anyone

Dan Korn
June 8th, 2011, 12:57 PM
return FormatDate(Field("Field13", "mm/dd"));
Your syntax is wrong. The first closing parend needs to go before the comma, like so:
return FormatDate(Field("Field13"), "mm/dd");The Field function takes one parameter, and the FormatDate function takes two. You were passing two parameters to Field (the second of which was ignored), and only one to FormatDate. I suppose the FormatDate function should throw a more meaningful error in this case.

n2_space
October 25th, 2011, 06:35 AM
I'm confused, seeing what is written above I put this in:


return FormatDate(Field("INJECTION DATE"), "mm/dd/yyyy");


but it does not work.... thoughts?

Dan Korn
October 25th, 2011, 08:58 AM
I'm confused, seeing what is written above I put this in:
return FormatDate(Field("INJECTION DATE"), "mm/dd/yyyy"); but it does not work.... thoughts?
What's the value of the data field? You might need to do this instead:
return FormatDate(DateFromString(Field("INJECTION DATE")), "mm/dd/yyyy");
But that still might not work, depending on what's in the data. You might need some custom parsing code.

WestPress
February 28th, 2012, 02:29 PM
Hey keangirl, not sure if you saw this post or not, or even if you still need it, but this is an awesome library for formatting dates that I use:

http://forums.printable.com/showthread.php?p=8085#poststop